IBM PC & CLONES Here's how to use BASIC on the IBM PC. (The IBM PC Junior, IBM PC XT, IBM PC AT, IBM PS/1, IBM PS/2, and IBM Valuepoint are similar. So are the microcomputers that are called ``IBM-compatible'' or ``IBM clones''.) The keyboard (page 324) The original IBM PC contained 83 keys, placed like this: ÚÄÄÄÂÄÄÄ¿ ÚÄÄÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ ÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ ³ ³ ³ ! ³ @ ³ # ³ $ ³ % ³ ^ ³ & ³ * ³ ( ³ ) ³ _ ³ + ³ ³ ³ ³ ³F1 ³F2 ³ ³Esc ³ 1 ³ 2 ³ 3 ³ 4 ³ 5 ³ 6 ³ 7 ³ 8 ³ 9 ³ 0 ³ - ³ = ³ Backsp ³ NumLock ³ScrollLock³ ÃÄÄÄÅÄÄÄ´ ÃÄÄÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄ ÁÄÄÂÄÄÄÄÄÅÄÄÄÄÂÄÄÄÄÅÄÄÄÄÂÄÄÄÄÄ´ ³ ³ ³ ³LeftTab³ Q ³ W ³ E ³ R ³ T ³ Y ³ U ³ I ³ O ³ P ³ { ³ } ³ ³ 7 ³ 8 ³ 9 ³ ³ ³F3 ³F4 ³ ³Tab ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ [ ³ ] ³ ³Home³  ³PgUp³ - ³ ÃÄÄÄÅÄÄÄ´ ÃÄÄÄÄÄÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁ ÄÄÄ´ ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄ´ ³ ³ ³ ³ ³ A ³ S ³ D ³ F ³ G ³ H ³ J ³ K ³ L ³ : ³ " ³ ~ ³ ³ 4 ³ 5 ³ 6 ³ ³ ³F5 ³F6 ³ ³Ctrl ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ; ³ ' ³ ` ³Enter³  ³ ³ þ ³ ³ ÃÄÄÄÅÄÄÄ´ ÃÄÄÄÄÄÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁ ÄÄÄÅÄÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´ ³ ³ ³ ³ ³ ³ | ³ Z ³ X ³ C ³ V ³ B ³ N ³ M ³ < ³ > ³ ? ³ ³PrtSc³ 1 ³ 2 ³ 3 ³ ³ ³F7 ³F8 ³ ³Shift ³ \ ³ ³ ³ ³ ³ ³ ³ ³ , ³ . ³ / ³Shift³ * ³End ³  ³PgDn³ ³ ÃÄÄÄÅÄÄÄ´ ÃÄÄÄÄÄÄÁÄÄÂÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÂÄÄÁÄÄ ÄÄÄÅÄÄÄÄÄÁÄÄÄÄÅÄÄÄÄÁÄÄÄÄ´ ³ ³ ³ ³ ³ ³ ³ ³ 0 ³ . ³ ³ ³F9 ³F10³ ³Alt ³ Space ³CapsLock³ Ins ³ Del ³ + ³ ÀÄÄÄÁÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄ ÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÙ In that diagram, I wrote the words ``Shift'', ``Backsp'', ``Tab'', and ``Enter''; but if you look at the actual IBM PC keyboard, you'll see arrows on those keys instead. The SHIFT key shows an arrow pointing up; the BACKSPACE key shows an arrow pointing to the left; the TAB key shows arrows crashing into walls; and the ENTER key shows an arrow that's bent. IBM put arrows on those keys instead of words, to help people who don't read English. In January 1986, IBM began selling a fancier keyboard, which contained 101 keys: ÚÄÄÄ¿ ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄ¿ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³Esc³ ³F1 ³F2 ³F3 ³F4 ³ ³F5 ³F6 ³F7 ³F8 ³ ³F9 ³F10³F11³F12³ ³PrintScreen³ScrollLock³Pause³ ÀÄÄÄÙ ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÙ ÚÄÄÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÄ¿ ³ ~ ³ ! ³ @ ³ # ³ $ ³ % ³ ^ ³ & ³ * ³ ( ³ ) ³ _ ³ + ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ` ³ 1 ³ 2 ³ 3 ³ 4 ³ 5 ³ 6 ³ 7 ³ 8 ³ 9 ³ 0 ³ - ³ = ³ Backsp³ ³ Insert ³ Home ³ PageUp ³ ³NumLock³ / ³ * ³ - ³ ÃÄÄÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÄÄÄÄ´ ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄ´ ÃÄÄÄÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄ´ ³LeftTab³ Q ³ W ³ E ³ R ³ T ³ Y ³ U ³ I ³ O ³ P ³ { ³ } ³ | ³ ³ ³ ³ ³ ³ 7 ³ 8 ³ 9 ³ ³ ³Tab ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ [ ³ ] ³ \ ³ ³ Delete ³ End ³PageDown³ ³ Home ³  ³PgUp³ ³ ÃÄÄÄÄÄÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÄÄÄÄÄ´ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙ ÃÄÄÄÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´ ³ ³ ³ A ³ S ³ D ³ F ³ G ³ H ³ J ³ K ³ L ³ : ³ " ³ ³ ³ 4 ³ 5 ³ 6 ³ ³ ³CapsLock³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ; ³ ' ³ Enter³ ³  ³ ³ þ ³ + ³ ÃÄÄÄÄÄÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÄÄÄÄÄÄÄ´ ÚÄÄÄÄÄÄÄÄ¿ ÃÄÄÄÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄ´ ³ ³ Z ³ X ³ C ³ V ³ B ³ N ³ M ³ < ³ > ³ ? ³ ³ ³ ³ ³ 1 ³ 2 ³ 3 ³ ³ ³Shift ³ ³ ³ ³ ³ ³ ³ ³ , ³ . ³ / ³ Shift³ ³  ³ ³ End ³  ³PgDn³ ³ ÃÄÄÄÄÄÄÄÄÄÄÁÂÄÄÁÄÄÂÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÂÁÄÄÄÁÂÄÄÄÄÄÄÄÄÄ´ ÚÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄ¿ ÃÄÄÄÄÄÄÄÁÄÄÄÄÅÄÄÄÄ´ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ . ³ ³ ³Ctrl ³ Alt ³ Space ³ Alt ³ Ctrl³ ³  ³  ³ þ ³ ³ Ins ³Del ³Enter³ ÀÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÁÄÄÄÄÄÙ At first, that fancier keyboard was available just on an IBM computer called the IBM RS. Later, IBM made that keyboard available for the newest versions of the IBM PC XT and IBM PC AT and for the IBM PS/2. Today, IBM sells just that 101-key keyboard; it no longer sells the old 83-key keyboard. Which keyboard does your computer have? If you have an 83-key keyboard, double-check to make sure you found the important keys correctly. . . . The left SHIFT key is above the ALT key. The right SHIFT key is above the CAPS LOCK key. The BACKSPACE key is in the top row and left of the NUM LOCK key. The TAB key is left of the Q. The ENTER key is above the PRT SC key. To type a number easily, use the keys in the top row of the main part of the keyboard. (For example, to type 4, press the key that has a 4 and a dollar sign.) Do not press the number keys on the right side of the keyboard: they produce numbers only if the NUM LOCK key is pressed beforehand, by you or the computer. If the NUM LOCK key was pressed to produce numbers, and you want to stop making those keys produce numbers, just tap the NUM LOCK key again. Get started (page 325) Start by obeying the instructions on pages 79 and 80. If you have a hard disk, those instructions make the computer say ``C:\>''. If you don't have a hard disk, those instructions make the computer say ``A>'' or ``A:\>''. Versions of BASIC Two popular versions of BASIC have been invented for the IBM PC. The old version is called GWBASIC. (The GW stands for ``gee whiz''). The new version is called QBASIC. (The Q stands for ``quick''). MS-DOS versions 5 & 6 include a pair of files that make the computer understand QBASIC. Those files are called ``QBASIC.EXE'' and ``QBASIC.HLP''. Most older versions of MS-DOS include a file that makes the computer understand GWBASIC. That file is usually called ``GWBASIC.EXE''; but some versions of MS-DOS call it ``BASIC.COM'' or ``BASICA.COM'' instead. Some versions of MS-DOS lack the file altogether and can't do BASIC. Getting into QBASIC If you're planning to use QBASIC (because you bought MS-DOS version 5 or 6), type ``qbasic'' after the C prompt, like this: C:\>qbasic The computer will say: Welcome to MS-DOS QBasic Press the Esc key, then the F6 key. Instead of saying ``OK'', the computer will show a blinking line near the screen's bottom left corner. Getting into GWBASIC If you're planning to use GWBASIC (because you bought an old version of MS-DOS), here's what to do. . . . If you have a hard disk, try typing: C:\>gwbasic If the computer gripes (by saying ``Bad command or file name''), try typing: C:\>basica If the computer still gripes (by saying ``Bad command or file name'' again), try typing: C:\>basic If the computer still gripes (by saying ``Bad command or file name'' again), try saying ``dos\gwbasic'' or ``dos\basica'' or ``dos\basic''. If you do not have a hard disk, find the floppy that contains GWBASIC.EXE or BASICA.COM or BASIC.COM. Insert that floppy into drive A and say ``gwbasic'' or ``basica'' or ``basic''. When you get into GWBASIC successfully, the computer will say the word ``Ok''. If the computer does not say the word ``Ok'', you probably used the wrong version of DOS. Make sure your version of DOS came from your computer's manufacturer. For example, if IBM built your computer, use IBM's PC-DOS, not a clone version of MS-DOS. If a clone company built your computer, use your clone's version of MS-DOS, not IBM's PC-DOS. Using the wrong version of DOS makes the computer print a strange message, the screen go crazy, or the keyboard stop working. If you have an IBM PC Junior, buy the BASIC cartridge and put it into the left cartridge slot before you turn the computer on. (That cartridge makes the Junior understand CIRCLE, PAINT, PLAY, TIMER, and the BASIC words for disks.) If your Junior is attached to a monitor instead of a TV, type ``width 80'' after the computer says ``Ok''. How to leave QBASIC When you finish using QBASIC, say ``File eXit'' (by tapping the Alt key, then the F key, then the X key). If the computer asks ``Save it now?'', say ``No'' (by pressing N). How to leave GWBASIC When you finish using GWBASIC, type the word ``system'' (and press ENTER). Math (page 326) In QBASIC, when you give a command (such as PRINT 5+2), the answer appears at the bottom of the screen; after you examine the answer, press ENTER. Three steps (page 328) The way to program depends on whether you're using GWBASIC or QBASIC. GWBASIC In GWBASIC, if you're too lazy to type the word RUN, just press the F2 key, which makes the computer automatically type the word RUN for you and automatically press the ENTER key for you. On an PC Junior, press the Junior's Fn key before F2. QBASIC In QBASIC, here's how to program your computer. First, say ``File New'' (by pressing the Alt key, then the F key, then the N key). If the computer asks ``Save it now?'', say ``No'' (by pressing the N key again). Next, make sure the blinking underline is in the top part of the screen. (If the blinking underline is in the bottom part, move it to the top part by pressing the F6 key). Then type your program. You do not have to type a number in front of each line; those numbers are optional. Instead of typing ___ 1 print "I love you" 2 print "you turn me on" 3 print "let's get married" you can type: print "I love you" print "you turn me on" print "let's get married" Finally, say ``Run'' (by pressing the F5 key). At the bottom of the screen, the computer will print everything you requested; it will print: I love you you turn me on let's get married When you finish examining that printing, press the ENTER key. Another example (page 329) In QBASIC, do not type the word LIST, since the top part of the screen shows the list of your program already. In GWBASIC, if you're too lazy to type the word LIST, just press the F1 key, which makes the computer automatically type the word LIST for you. Then press ENTER. On a PC Junior, press the Fn key before F1. Correcting errors (page 330) In QBASIC, if you mess up a line, do not retype it underneath. Instead, press the arrow keys to move to the first character you want to revise, then repeatedly press the DELETE (or Del) key until all the bad characters disappear, then type the characters you wish to insert, then press the down-arrow key. What if computer gripes? (page 330) If the computer gripes at you, press the ENTER key immediately. After pressing the ENTER key, correct the error by retyping the line that the computer griped about. Rearranging your program (page 331) In QBASIC, the computer does not rearrange your program. Here's how to make QBASIC erase a line. Move to that line (by pressing the arrow keys). Then, while holding down the Ctrl key, tap the Y key (which means ``Yank out the line''). Here's how to make QBASIC insert a new line. Move to where you want the new line to begin. Then, while holding down the Ctrl key, tap the N key (which means ``New line''). Ranges of lines (page 332) QBASIC doesn't understand ranges of lines. Arrow keys (page 332) The DELETE key says ``Del'' on it. The INSERT key says ``Ins'' on it. In QBASIC, do not press the INSERT key, and do not press the ENTER key at the end of your correction. Clear the screen (page 333) Your keyboard lacks a CLEAR key. To clear the screen, give the CLS command. In GWBASIC, here's another way to clear the screen: while holding down the Ctrl key, tap the HOME key. (On a PC Junior do this instead: While pressing Ctrl, tap Fn then HOME.) Print on paper (page 333) There is no key marked ``PRINT''. To print a screen dump, do this instead: if your keyboard is modern (and has 101 keys), press the key marked ``PRINT SCREEN''. If your keyboard is old-fashioned (and has just 83 keys), press the PrtSc key while holding down the SHIFT key. If you have a PC Junior, press the Fn key then the PrtSc key. Most computers lack an ECHO key. In QBASIC, you cannot echo. In GWBASIC, here's how to echo: press the PrtSc key while holding down the Ctrl key. To echo on the PC Junior, press the Fn key then the ECHO key. In QBASIC, instead of saying LLIST do this: say ``File Print'' (by pressing Alt then F then P), then press ENTER. GO TO (page 334) The BREAK key is the last key in the top row. If your keyboard has 83 keys, the BREAK key says SCROLL LOCK on it; if your keyboard has 101 keys, the BREAK key says PAUSE on it. The BREAK key works only if you simultaneously hold down the Ctrl key. So to abort a program, do this: hold down the Ctrl key; and while you keep holding down the Ctrl key, tap the BREAK key. PC Junior Press the Fn key before pressing BREAK. You do not have the press the Ctrl key. QBASIC Instead of typing this ___ 10 print "cat" 20 print "dog" 30 go to 10 you can type: 10 print "cat" print "dog" go to 10 Instead of using a number (such as 10), you can use a name (such as JOE), but you must put a colon after the name, like this: joe: print "cat" print "dog" go to joe After you abort a QBASIC program, pressing F5 makes the computer continue where it left off; pressing SHIFT with F5 makes the computer run the program from the beginning. STOP (page 336) In QBASIC, when the computer encounters the word STOP in a program, the computer stops running the program. Then it lists the program and highlights the line of your program that said STOP. Save on disk (page 336) Before using a blank disk, make sure the disk has been formatted. To learn how to format a disk, read my MS-DOS chapter. In QBASIC, instead of typing SAVE ``JOE'', do this: say ``File Save'' (by pressing Alt then F then S), then type JOE (and press ENTER). QBASIC doesn't understand the word ``FILES''. How to use other drives When you tell the computer to save JOE, the computer normally puts JOE into drive C's root directory (if you have a hard disk) or drive A's directory (if you have no hard disk). If you want the computer to put JOE into drive B instead, say ``b:joe'' instead of ``joe''. To make GWBASIC print the names of all the programs in drive B, type this: files "b:" Exception: if you're using an obsolete version of DOS (version 1 or version 1.05 or version 1.1), you must type this instead: files "b:*.*" How to choose a name (page 337) Your program's name can be short (such as JOE) or long: up to 8 characters. The name's first character must be a letter; the remaining characters should be letters or digits. Load from disk (page 337) In QBASIC, instead of typing LOAD ``JOE'', do this: say File Open (by pressing Alt then F then O), then type JOE (and press ENTER); if the computer asks ``Save it now?'', say ``No'' (by pressing N). Edit the disk (page 337) QBASIC doesn't understand RENAME at all. In GWBASIC, instead of saying RENAME ``JOE'' TO ``FRED'', say NAME ``JOE.BAS'' AS ``FRED.BAS'', to emphasize that JOE was written in BASIC. Space on the disk (page 337) QBASIC doesn't understand KILL at all. In GWBASIC, instead of saying KILL ``JOE'', say KILL ``JOE.BAS''. Tapes (page 337) Since practically everybody who buys an IBM PC uses disks instead of tapes, I won't bother explaining IBM's tape system. FOR . . . NEXT (page 355) To indent, you can hit the SPACE bar repeatedly. But to indent more easily, hit the TAB key (which is left of the Q key and has arrows on it). In QBASIC, if you indent a line (by hitting the SPACE bar repeatedly, or by hitting the TAB key), the computer will assume you want to indent the line underneath also, and so the computer will automatically indent that line for you. If the computer indents a line that you don't want indented, erase the indentation by hitting the BACKSPACE key. Renumbering (page 367) QBASIC doesn't understand RENUM. The PAUSE key (page 367) If your keyboard has just 83 keys, it lacks a PAUSE key, so to pause do this instead: while holding down the Ctrl key, tap the NUM LOCK key. To make the PC Junior pause, press the Fn key then the PAUSE key. To stop pausing, press the ENTER key. Zones (page 368) Your screen has five zones. Zones 1-4 are each 14 characters wide. Zone 5 is 24 characters wide. How many pixels? (page 372) IBM-compatible computers can handle several different screen modes: Mode Video card Pixels Colors 1 CGA (or EGA, MCGA, VGA) 320 by 200 4 2 CGA (or EGA, MCGA, VGA) 640 by 200 2 3 Hercules monochrome720 by 348 2 4 Olivetticolor 640 by 400 2 7 EGA (or VGA) 320 by 200 16 8 EGA (or VGA) 640 by 200 16 9 EGA (or VGA) 640 by 350 4 or 16 10 EGA mono (or VGA mono) 640 by 350 4 11 MCGA (or VGA) 640 by 480 2 12 VGA 640 by 480 16 13 MCGA (or VGA) 320 by 200 256 For example, here's what row 1 of that chart means: To use mode 1, your video card must be CGA (or EGA or MCGA or VGA). That mode lets you use 320 values of X (numbered from 0 to 319). That mode lets you use 200 values of Y (numbered from 0 to 199). That mode lets the screen display 4 colors simultaneously. Special mono modes Modes 3 and 10 require monochrome monitors; they do not work with color monitors. In mode 3, you have just 2 ``colors'': black and white. Special color modes In mode 9, you usually get 16 colors, but you get just 4 colors if the video card is EGA having just 64K of video RAM. Mode 4 requires a color video card made by Olivetti. That card is included in the AT&T 6300 computer. Text mode There's also a ``mode 0'', which works on all computers and produces just text (no graphics). Versions of BASIC QBASIC (which comes with DOS 5) understands all modes. GWBASIC understands less: GWBASIC using DOS 1, 1.1, 2, 2.1, or 3 understands just modes 0, 1, and 2. GWBASIC using DOS 3.1 or 3.2 understands modes 0, 1, 2, and 3. GWBASIC using DOS 3.3 or 4 understands modes 0 through 10. Which mode to choose If you're using QBASIC (which understands all modes), here's which mode to choose: Video card Which mode to choose Hercules monochrome 3 Olivetti color 4 CGA color 1 (for many colors) or 2 (for many pixels) EGA mono or VGA mono 10 EGA color 9 MCGA color 11 (for many pixels) or 13 (for many colors) VGA color 12 (for many pixels) or 13 (for many colors) For GWBASIC using DOS 3.3 or 4, use that same chart, but choose mode 9 instead of modes 11, 12, and 13. For GWBASIC using DOS 3.1 or 3.2, use this chart instead: Video card Which mode to choose Hercules monochrome 3 any other video card 1 (for many colors) or 2 (for many pixels) How to change mode Before giving any commands about pixels, tell the computer which mode you want. For example, if you want mode 1, say: screen 1 Whenever you finish using pixels, return to text mode by saying: screen 0 width 80 The ``width 80'', which makes sure the screen will display 80 characters per line, is necessary only if you'd been using mode 1, 7, or 13. PC Junior The PC Junior handles modes 0, 1, and 2. It also handles special versions of modes 3, 4, 5, and 6: PC Junior modePixelsColors 3 160 by 20016 4 320 by 200 4 5 320 by 20016 6 640 by 200 4 Modes 5 and 6 require at least 128K of RAM and require that you give this command beforehand: clear,,,32768 Fundamental shapes (page 372) Say PSET instead of PLOT. Colors (page 372) In modes 4, 7, 8, and 12, you can choose from the 16 colors listed on page 372. In mode 1, you must choose from these 4 colors instead: 0. black 1. cyan (greenish blue) 2. magenta (purplish red) 3. cream (yellowish white) For example, if you type ___ line (0,0)-(100,0),2 the computer will draw a line using color 2, which is magenta. In modes 2, 3, and 11, you must choose from these 2 colors instead: 0. black 1. white In mode 10, you have these 4 choices: 0. black 1. cream 2. blink 3. white In mode 9, you can usually choose from the 16 colors mentioned on page 372; but if you're using mode 9 with an EGA card having just 64K of RAM, you're restricted to the 4 colors used in mode 1. In mode 13, you can choose from the 16 colors listed on page 372 ___ and many more colors, too! Here's the spectrum: 0 through 7: black, blue, green, cyan, red, magenta, brown, cream 8 through 15: same colors as above, but lighter 16 through 31: shades of gray (from dark to light) 32 through 55: color blends (from blue to red to green to blue again) 56 through 79: same color blends, but lighter 80 through 103: same color blends, but even lighter 104 through 175: same as 32 through 103, but darker 176 through 247: same as 104 through 175, but even darker 248 through 255: black Advanced commands (and page #) PLAY (page 374). In the PLAY command, you can use the symbol ``>'' to mean ``go up an octave'', and you can use the symbol ``<'' to mean ``go down an octave''. For example, if you say ___ play "g>cd'' and ``<'' don't work. The lowest note the computer can play (which is the C in octave 0) is called ``note 1''. The highest note the computer can play (which is the B in octave 6) is called ``note 84''. To make the computer play note 84, type this: play "n84" To make the computer play its lowest note (1), then its middle note (42), then its highest note (84), type this: play "n1n42n84" PC Junior. If you turn up the volume on your TV or monitor, and then say SOUND ON, you can make the Junior's three voices sing simultaneously, like this: play "gab","efg","ccd" While the first voice is singing ``gab'', the second voice sings ``efg'', and the third voice sings ``ccd''. Random integers (388). Instead of saying just RANDOMIZE, say RANDOMIZE TIMER. Exception: if you're using GWBASIC with an obsolete version of DOS (version 1 or 1.05 or 1.1), you must say RANDOMIZE VAL(RIGHT$(TIME$,2)). To get a random integer between 1 and 5, instead of saying RND(5), say 1+INT(RND*5). Types of numbers (397). In GWBASIC, if your program involves trigonometry (SIN, COS, TAN, ATN) or exponents (^, SQR, EXP, LOG), and you want those computations done with double-precision accuracy, you must say ``gwbasic/d'' (instead of just ``gwbasic''), or say ``basica/d'' (instead of just ``basica''). In QBASIC, double-precision numbers can go higher than real numbers: the highest permissible double-precision number is about 1D308. Accuracy (397). In QBASIC, if you type a double-precision number, the computer handles just the first 15 digits accurately. Joystick (408). The coordinates of joystick A are STICK(0) and STICK(1). The coordinates of joystick B are STICK(2) and STICK(3). When the computer comes to a line that mentions STICK(0), the computer looks at both joysticks and computes STICK(0), STICK(1), STICK(2), and STICK(3). If your program mentions STICK(1) or STICK(2) or STICK(3), without mentioning STICK(0), the computer won't look at the joysticks. Mouse (408). Neither GWBASIC nor QBASIC is designed to control a mouse. Peek (414). Your computer's memory is divided into segments. Each segment contains 64K of RAM or ROM. Before saying PEEK or POKE, tell the computer which segment to use. For example, if you want the computer to use segment 3, begin your program by saying: 10 def seg=3 If you then say PRINT PEEK(50000), the computer will peek at the 50000th cell of segment 3. If you forget to say DEF SEG, or say just ___ 10 def seg without putting a number afterwards, the computer will use its ``favorite'' segment. Although you can play cute tricks by using the words PEEK and POKE, most IBM programmers avoid those words, for three reasons: 1. PEEK and POKE are awkward to use, because you must remember to say DEF SEG beforehand. 2. The PEEKs and POKEs that work on your computer system might not work on your friend's computer system, because different clones and DOS versions use different memory cells. 3. DOS and BASIC include many commands that are easier than PEEK and POKE and accomplish similar goals. To learn about them, browse through the DOS and BASIC manuals that came with your computer. If you insist on fiddling with PEEKs and POKEs, read David Schneider's magazine article, which reveals the secrets of dozens of memory cells. Part 1 of his article is on pages 201-218 of the 11/12/85 issue of PC Magazine; part 2 is on pages 187-208 of the 11/26/85 issue. The articles are excerpted from the end of his book, called the Handbook of BASIC for the IBM PC Revised and Expanded, published by the Brady Book division of Simon & Schuster. PUT (417). In GWBASIC, if you want the record length to be more than 128, you must warn the computer. For example, to warn the computer that you'll want a record length of 400, say ``gwbasic/s:400'' (instead of just ``gwbasic''), or say ``basica/s:400'' (instead of just ``basica''). APPLE MAC Here's how to use BASIC on Apple's Mac Plus computer. (Other Macs are similar.) Microsoft BASIC (page 322) When you buy the computer, make sure you also buy Microsoft Quick BASIC. It costs $65 and comes on two disks. It works an all Macs except the most It works only on modern Macs (such as the Mac Plus, Mac SE, Mac SE/30, Mac Classic, Mac LC, Mac 2, Mac 2cx, Mac 2ci, Mac 2si, and Mac 2fx.) It does not work on older Macs (the 128K Mac, 512K Mac, and 512KE Mac), since they contain obsolete ROM chips. Make sure you buy ``Microsoft Quick BASIC'', not just ``Microsoft BASIC'', which is obsolete. Here's how to use Microsoft Quick BASIC. (I'll also explain how old ``Microsoft BASIC'' differs.) The keyboard (page 324) The keys are placed like this: ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄÄ¿ ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄ¿ ³ ~ ³ ! ³ @ ³ # ³ $ ³ % ³ ^ ³ & ³ * ³ ( ³ ) ³ _ ³ + ³ ³ ³ ³ ³ ³ ³ ³ ` ³ 1 ³ 2 ³ 3 ³ 4 ³ 5 ³ 6 ³ 7 ³ 8 ³ 9 ³ 0 ³ - ³ = ³Backsp³ ³Clr³ = ³ / ³ * ³ ÃÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÄÄÄ´ ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄ´ ³ ³ Q ³ W ³ E ³ R ³ T ³ Y ³ U ³ I ³ O ³ P ³ { ³ } ³ ³ ³ ³ ³ ³ ³ ³Tab ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ [ ³ ] ³ ³ ³ 7 ³ 8 ³ 9 ³ - ³ ÃÄÄÄÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÙ ³ ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄ´ ³ ³ A ³ S ³ D ³ F ³ G ³ H ³ J ³ K ³ L ³ : ³ " ³ ³ ³ ³ ³ ³ ³ ³Caps ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ; ³ ' ³ Return³ ³ 4 ³ 5 ³ 6 ³ + ³ ÃÄÄÄÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÄÄÂÄÄÄ´ ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄ´ ³ ³ Z ³ X ³ C ³ V ³ B ³ N ³ M ³ < ³ > ³ ? ³ ³ ³ ³ ³ ³ ³ ³ ³Shift ³ ³ ³ ³ ³ ³ ³ ³ , ³ . ³ / ³Shift³  ³ ³ 1 ³ 2 ³ 3 ³ ³ ÃÄÄÄÄÄÄÂÄÁÄÄÄÁÄÂÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÄÄÅÄÄÄ´ ÃÄÄÄÁÄÄÄÅÄÄÄ´ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³Option³Command³ Space ³ \ ³  ³ þ ³  ³ ³ 0 ³ . ³Enter³ ÀÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ ÀÄÄÄÄÄÄÄÁÄÄÄÁÄÄÄÄÄÙ To the left of the SPACE bar, you'll see the COMMAND key. In the diagram, I wrote the word ``Command'' on that key; but if you look at your actual Mac keyboard, you'll see a picture of a highway's cloverleaf on that key instead. The keyboard contains a RETURN key and also an ENTER key. When you're using BASIC, those keys do the same thing as each other. You'll probably prefer the RETURN key, since your pinky can reach it more easily. Get started (page 325) To start using the Mac, read the chapter that explains the Mac Finder. Practice what's in that chapter, before you start playing with BASIC. When you've practiced what's in that chapter, here's how to start using BASIC. If you own an external hard drive, turn it on, and wait for the clicking to stop. Then turn on the Mac. Adjust the Mac's brightness knob, until you can read the screen. If the screen doesn't show a trash can, insert System Tools Disk #1, then eject it (by choosing Eject from the File menu). Now your Mac screen shows the trash can, and your floppy-disk drive is empty. Insert the Microsoft Quick BASIC disk whose label says ``Program''. Then double-click the Program icon. (If you're using old Microsoft BASIC instead, insert the disk whose label says ``Interpreter'', then double-click the Microsoft BASIC icon.) The disk contains two versions of BASIC. The binary version computes quickly: it's used by scientists who want blazing speed. The decimal version computes slowly but handles decimals with extra accuracy: it's used by accountants who are in no rush, but insist on never being off by a penny. To choose the binary version, double-click the ``Microsoft Quick BASIC (b)'' icon. To choose the decimal version instead, double-click the ``Microsoft Quick BASIC (d)'' icon instead. The icon will explode. If you're using Microsoft Quick BASIC (instead of old Microsoft BASIC), and you don't have a hard disk or second floppy drive, the computer will tell you to swap disks 16 times. Obey the computer, and be patient! Make the command window appear on the screen and be active. To do that, choose Command from the Windows menu, or use this short cut: while holding down the COMMAND key, type a period. (Old Microsoft BASIC permits an even shorter cut: just click the word ``Command'' at the bottom of the screen.) Instead of saying OK, the computer shows a blinking vertical line. How to quit Whenever you're done using BASIC, choose Quit from the File menu (or tap the Q key while holding down the COMMAND key). Then the computer might say: Current program is not saved. Do you want to save it before proceeding? Cancel No Yes If the computer says that, click the word ``No''. Then choose Shut Down from the Special menu. When the computer says ``You may now switch off your Macintosh safely'', turn off the Mac and then any external hard drive. Math (page 326) When you type a command (such as PRINT 5+2), the command appears at the bottom of the screen, in the command window. The computer prints the answer (7) at the top of the screen, in the output window. Long commands on small screens (page 328) Keep your commands short. If you type a command that's too long to fit on a line, the computer has difficulty handling it. Three steps (page 328) Programming your computer consists of three steps. . . . Step 1: say NEW But instead of typing the word NEW, choose New from the File menu. If you're lucky, you'll see horizontal stripes next to the word ``List''. If you're unlucky, the computer will say: Current program is not saved. Do you want to save it before proceeding? Cancel No Yes Click the word ``No''. You'll see horizontal stripes next to the word ``List''. Step 2: type your program Whatever you type will appear underneath the word ``Listing'', in the list window. (Old Microsoft BASIC says ``List'' instead of ``Listing''.) You do not have to type a number in front of each line; those numbers are optional. Instead of typing ___ 1 print "I love you" 2 print "you turn me on" 3 print "let's get married" you can type: print "I love you" print "you turn me on" print "let's get married" Step 3: run the program Instead of typing the word RUN and pressing ENTER, choose Run Program from the Run menu (or tap the R key while holding down the COMMAND key). (Old Microsoft BASIC's Run menu says ``Start'' instead of ``Run Program''.) The list window will disappear. The computer will print everything you requested; it will print: I love you you turn me on let's get married Then the list window will reappear, and you'll see your program in the window again. Summary of those steps Here's the rule: if you type a list of instructions in the list window, the computer won't obey those instructions until you choose Run Program (from the Run menu or by pressing COMMAND R). Changing the list window If your program's too long to fit in the list window, the window will show just part of your program. To see the rest of your program, use the window's scroll bars. Clicking the window's zoom box makes the window expand, so that it consumes the entire screen. Clicking the zoom box again makes the window shrink back to its original size. (If your old Microsoft BASIC lacks a zoom box, double-click the word ``List'' instead.) Clicking the close box makes the window disappear. To make the window reappear, choose List from the Windows menu (or tap the L key while holding down the COMMAND key). Another example (page 329) Do not type the word LIST. It's usually unnecessary, since the computer tries to always show the list of your program on the screen. If the computer ever fails to show the list on the screen, do not type the word LIST: instead, choose List from the Windows menu (or press COMMAND L). Correcting errors (page 330) If you mess up a line, do not retype it underneath. Instead, do the following. . . . Point at the right edge of the rightmost character that you want to revise. Click once. Repeatedly press the key marked BACKSPACE or DELETE, until all the bad characters disappear. Then type the characters you wish to insert. When you've finished typing them, click underneath the entire program. What if computer gripes? (page 330) If you accidentally type PRIMT instead of PRINT, when you run the program the computer will gripe by saying: Undefined subprogram It will also put your program on the screen, and will draw a box around the line it griped about. Click the word ``OK'', then revise the bad line. Rearranging your program (page 331) The computer does not rearrange your program! The computer does not put the lines in numerical order! If you type 80, the computer will not erase line 80! How to erase a line Point slightly left of the leftmost character in the line ___ so that you're pointing at the gap between the leftmost character and the window's left wall. Press the mouse's button; while you keep pressing the button, drag down one line, but without touching any characters. The line you want to erase will become black. Lift your finger off the button. Press the BACKSPACE key. The line will disappear. Click underneath the entire program. How to insert a new line Click at the right edge of the rightmost character of the line above. Press the RETURN key. You'll see a gap to put the new line in. Type the new line; do not press the RETURN key at the end of it. Click underneath the entire program. Ranges of lines (page 332) To list from line 30 to the end of your program, make the command window active (by clicking it or choosing Command from the Windows menu or pressing the COMMAND and period keys simultaneously). Then type: list 30 The computer does not understand ``LIST 30-80'' or ``LIST -80''. To delete lines 30 through 80, make the command window active and type: delete 30-80 After you type that command (and press the RETURN key), make the list window active (by clicking it or choosing List from the Windows menu). Arrow keys (page 332) To insert some text between two characters, click at the gap between the two characters, then type the text. To delete a group of characters, point at the left edge of the first character in the group, then drag to the right edge of the last character in the group. The characters you want to delete will turn black. Lift your finger off the mouse's button. Press the BACKSPACE key. The characters will disappear. Clear the screen (page 333) The CLEAR key doesn't work. Print on paper (page 333) Your keyboard lacks a PRINT key. Instead of pressing a PRINT key, press the CAPS LOCK key, so that it stays down; then hold down the SHIFT and COMMAND keys; while you keep holding down the SHIFT and COMMAND keys, tap the 4 key. The printer will print onto paper a copy of the entire screen. When the printer has finished, tap the CAPS LOCK key, so that it pops back up. That method works if your printer's an Imagewriter but not if it's a Laserwriter. Your keyboard lacks an ECHO key. Your computer understands LPRINT. Although your computer understands LLIST (if typed in the command window), an easier way to list your program on paper is to make the list window active, then choose Print from the File menu, then click OK. GO TO (page 334) Instead of typing this ___ 10 print "cat" 20 print "dog" 30 go to 10 you can type: 10 print "cat" print "dog" go to 10 If you delete the 10 from the top line, the computer will gripe when it sees ``go to 10''. Instead of using a number (such as 10), you can use a name (such as JOE), but you must put a colon after the name, like this: joe: print "cat" print "dog" go to joe To abort a program, choose Stop from the File menu, or tap the period key while holding down the COMMAND key. (Old Microsoft BASIC puts ``Stop'' in the Run menu instead of the File menu.) After you've aborted a program, if you wish to see a LIST, make the list window active (by choosing List from the Windows menu, or pressing COMMAND with L). How to single-step trace your program If a program runs faster than your eye can see or your mind can think, slow it down. To do that, instead of choosing Run Program from the Run menu, choose Step from the Run menu (or press COMMAND with T). That makes the computer do just one line or subline of your program; then it will pause. When you choose Step again, the computer will do the next line or subline. Each time you choose Step, the computer will do one more line or subline. Each time the computer does a line, it also shows the program in the list window, and puts a box around the line it just did. Love (page 334) If a program involves a semicolon with a GO TO, begin the program by saying WIDTH 61, like this: width 61 10 print "love"; go to 10 If you forget to say WIDTH 61, the computer will print just one line of love and then do nothing until you abort. STOP (page 336) When the computer encounters the word STOP in a program, the computer stops running the program. Then it lists the program and puts a box around the line of your program that said STOP. Save on disk (page 336) If you buy a blank disk and want to use it, you must initialize the disk. To learn how to do that, read the chapter that explains the Mac Finder. After you initialize that disk, you should copy ``Microsoft Quick BASIC (b)'' and ``System Folder'' onto that disk, by dragging those icons to that disk. To learn how to do that, read the chapter that explains the Mac Finder. You should not save programs on the original ``Microsoft BASIC'' disk. Instead, save your programs on a new disk that you turned into an easy-to-use BASIC disk. So before you write programs to save, turn off the computer, insert a new easy-to-use BASIC disk, and then turn the computer back on. Before typing SAVE ``JOE'' or FILES, make the command window active (by clicking it or choosing Command from the Windows menu or pressing the COMMAND and period keys simultaneously). Here's a short cut: instead of activating the command window and then saying SAVE ``JOE'', just choose Save from the File menu and then type JOE (followed by RETURN). How to choose a name (page 337) Your program's name can be short (such as JOE) or long: up to 31 characters. Short names are better, because they can fit in small windows. Load from disk (page 337) Before saying LOAD "JOE" or RUN "JOE", activate the command window. Here's a short cut: instead of activating the command window and saying LOAD "JOE", just choose Open from the File menu and double-click JOE. Edit the disk (page 337) Instead of saying RENAME ``JOE'' TO ``FRED'', say NAME ``JOE'' AS ``FRED''. Tapes (page 337) Your computer can't handle tapes. FOR . . . NEXT (page 355) To indent, you can hit the SPACE bar repeatedly. But to indent more easily, hit the TAB key. Hitting the TAB key has the same effect as hitting the SPACE bar four times. If you indent a line (by hitting the SPACE bar repeatedly, or by hitting the TAB key), the computer will assume you want to indent the line underneath also, and so the computer will automatically indent that line for you. If the computer indents a line that you don't want indented, erase the indentation, by hitting the BACKSPACE key four times. Renumbering (page 367) Your computer doesn't understand RENUM. The PAUSE key (page 367) Your keyboard lacks a PAUSE key ___ but you don't need one. When you list a program, the listing automatically pauses when the list window is filled. While running a program, you can stop temporarily (by choosing Stop from the File menu or pressing CONTROL with a period), then continue where you left off by choosing Continue from the Run menu (or pressing CONTROL with G). Old Microsoft BASIC understands Continue but not CONTROL with G. Zones (page 368) Your screen has 5 zones. Zones 1-4 are each 14 characters wide; zone 5 is 5 characters wide. Altogether, the screen is 61 characters wide. Those measurements are for standard-size characters. Your computer can also produce characters that are extra-narrow or extra-wide. Loops (page 369) If a program involves zones with a GO TO, begin the program by saying WIDTH 61, like this: width 60 10 print "hi", go to 10 How many pixels? (page 372) The X coordinate goes from 0 to 491. The Y coordinate goes from 0 to 297. The high-numbered pixels hide behind the list and command windows. To see those pixels, put this line at the bottom of your program ___ 9999 go to 9999 That line creates an infinite loop, which keeps the output window on the screen. When you finish staring at the pixels in the output window, abort the program by choosing Stop from the File menu (or press COMMAND with period). Fundamental shapes (page 372) Say PSET instead of PLOT. The computer draws each shape in black, on a white background. PAINT (page 372) Your computer doesn't understand the word PAINT. Colors (page 372) The standard Mac displays just black and white: it can't display any other colors. The code number for white is 0; the code number for black is 1. (Any even number produces white; any odd number produces black.) Advanced commands (and page #) PLAY (page 374). Your computer doesn't understand the word PLAY. Random integers (388). Instead of saying just RANDOMIZE, say RANDOMIZE TIMER. To get a random integer from 1 to 5, instead of saying RND(5), say 1+INT(RND*5). Types of numbers (397). BASIC comes in two versions ___ binary and decimal ___ which you choose by clicking the appropriate icon. Suppose you type a number containing a decimal point. If that number contains fewer than 7 digits, it's a real; if it contains more than 7 digits, it's double-precision; if it contains exactly 7 digits, the binary version treats it as a real, but the decimal version treats it as double-precision instead. Accuracy (397). If you type a double-precision number, the binary version handles it to an accuracy of 15 to 16 digits, but the decimal version handles it to an accuracy of just 14 digits. Variables (397). If a variable is simple (such as X), the binary version treats it as real, but the decimal version treats it as double-precision. Joystick (408). Your computer doesn't use a joystick. APPLE 2 FAMILY Here's how to use BASIC on the Apple 2c computer. (The Apple 2c+ and 2GS are similar.) I'll explain how the Apple 2, 2+, and 2e differ. The keyboard (page 324) On the Apple 2c, the keys are placed like this: ÚÄÄÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ ³ ³ ³ ³Reset³40 ³Keyboard³ ÀÄÄÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄÄ¿ ³ ³ ! ³ @ ³ # ³ $ ³ % ³ ^ ³ & ³ * ³ ( ³ ) ³ _ ³ + ³ ³ ³Esc ³ 1 ³ 2 ³ 3 ³ 4 ³ 5 ³ 6 ³ 7 ³ 8 ³ 9 ³ 0 ³ - ³ = ³Delete³ ÃÄÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÄÄÄ´ ³ ³ Q ³ W ³ E ³ R ³ T ³ Y ³ U ³ I ³ O ³ P ³ { ³ } ³ ³ ³ ³Tab ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ [ ³ ] ³ \ ³ ÃÄÄÄÄÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÄÄÄÄ´ ³ ³ A ³ S ³ D ³ F ³ G ³ H ³ J ³ K ³ L ³ : ³ " ³ ³ ³Control³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ; ³ ' ³ Return³ ÃÄÄÄÄÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÄÄÄÄÄÄ´ ³ ³ Z ³ X ³ C ³ V ³ B ³ N ³ M ³ < ³ > ³ ? ³ ³ ³Shift ³ ³ ³ ³ ³ ³ ³ ³ , ³ . ³ / ³ Shift³ ÃÄÄÄÄÄÄÄÄÂÁÄÄÂÁÄÄÄÁÄÄÄÁÂÄÄÁÄÄÄÁÄÄÂÁÄÄÄÁÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÄÄÂÄÄÄ´ ³ ³ ~ ³ ³ ³ ³ ³ ³ ³ ³ ³CapsLock³ ` ³OpenApple³ Space ³SolidApple³  ³ þ ³  ³  ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ The keys next to the SPACE bar are called the Apple keys. In the diagram, I wrote the words ``Open Apple'' and ``Solid Apple'' on those keys; but if you look at your actual Apple 2c keyboard, you'll see pictures of apples on those keys instead. There's no BACKSPACE key. To correct an error, press the left-arrow key, until you get back to where the error was. Then correct the error, by retyping. Then, if you wish, press the right-arrow key to move to the right. Your computer has a key marked DELETE, but it doesn't work when you're using BASIC. The ENTER key says RETURN on it. Apple 2e The Apple 2e keyboard lacks a 40 key and a KEYBOARD key. Apple 2 and 2+ The zero key is Swedish. The CONTROL key says CTRL on it. The letters are automatically capitalized. The keys are rearranged slightly. The following keys are missing: DELETE, TAB, CAPS LOCK, OPEN APPLE, SOLID APPLE, KEYBOARD, 40, down-arrow, up-arrow, left-bracket, right-bracket, backslash, and accent. Get started (page 325) Cut into the right side of your computer, you'll see a horizontal slot about 5 inches long. That slit's the entrance to the built-in drive. At the center of the slit is a door, which is the same color as the keys on the keyboard. To open the door, push it to the left; then it will automatically pop up. To close the door, push it down. Practice opening and closing it. Then open the door. Remove any disk from the built-in drive. Put the ``System Utilities ProDOS disk'' into the built-in drive; when inserting the disk, make sure the disk's label is on top of the disk, and make sure the disk's big oval cutout goes into the drive before the label does. After putting the disk into the drive, close the door. The computer's green power switch is at the computer's rear, and has the numbers 0 and 1 on it. Flip the power switch on, by pressing the 1. Turn on the TV or monitor. If you're using a TV, turn it to channel 3 or 4. To switch the computer from channel 3 to channel 4 or back to channel 3, flip the channel-selection switch, which is on the box attached to the back of the computer. If the writing on the TV looks fuzzy, adjust the TV's fine tuning. Adjust the screen's brightness and contrast. The computer will put several messages onto the screen. Eventually, you'll see the main menu, which looks like this: 1. Copy files 2. Delete files 3. Rename files 4. Lock/unlock files 5. Duplicate a disk 6. Format a disk 7. Identify and catalog a disk 8. Advanced operations 9. Exit system utilities Tap the 9 key, then tap the RETURN key twice. You'll see this symbol on the screen, at the upper-left corner: ] That symbol's called a bracket. It means everything's OK. Your computer prints a bracket instead of the word OK. You can make the characters on your screen be either thin or fat. The screen is wide enough to hold 80 thin characters per line, or 40 fat characters. Fat characters are easier to read, so choose fat characters if your eyesight is poor, or if you're using a cheap TV (which is blurry) instead of a monitor. To choose fat characters (40 per line), tap the ESC key, then the 4 key. To choose thin characters (80 per line), tap the ESC key, then the 8 key. Apple 2, 2+, and 2e The disk drive and its slot are in a separate box (instead of being built into the right side of the computer). If you have two disk drives, begin by using disk drive #1, not disk drive #2. Open the disk drive's door, by pulling the door out and up. Remove any disk from the drive. If you have a 2e, insert the ``ProDOS User's Disk''; if you have a 2 or 2+, insert the ``DOS 3.3 System Master Disk'' instead. When inserting the disk, make sure the disk's label is on top of the disk, and make sure the disk's big oval cutout goes into the drive before the label does. Close the door, by pushing it down and in. Turn on the TV or monitor. If you're using a TV, turn it on to channel 33. On the back of the computer, you'll see the computer's power switch, which is black. Flip it to the ON position. Here's what happens next, if you have a 2e: At the top of the screen, a message will appear briefly. If your 2e is old (manufactured before February 1985), the message says ``Apple ][''; if your 2e is new (or you've upgraded your old 2e), the message says ``Apple 2e''. Look at the message, to double-check whether your 2e is old or new. If your 2e is old, it can't handle lower-case letters well, so you must type just capitals. To type capitals easily, press the CAPS LOCK key, and make sure the CAPS LOCK key stays down. Your 2e will also print this menu: YOUR OPTIONS ARE: ? - TUTOR: PRODOS EXPLANATION F - PRODOS FILER (UTILITIES) C - DOS <-> PRODOS CONVERSION S - DISPLAY SLOT ASSIGNMENTS T - DISPLAY/SET TIME B - APPLESOFT BASIC Tap the B key. Regardless of whether you have a 2, 2+, or 2e, you'll eventually see this symbol near the screen's left edge: ] That symbol's called a bracket. It means everything's OK. Your computer prints a bracket instead of the word OK. The characters are fat (40 per line). Your Apple might be able to make the characters thin (80 per line), but your Apple handles thin characters reliably only if your Apple is a new 2e that also contains an 80-column card. If you have that kind of Apple and want thin characters, say ___ pr#3 and press the RETURN key. Ranges of lines (page 332) Instead of saying DELETE, say DEL. To delete lines 30 through 80, type this: del 30,80 Arrow keys (page 332) To edit line 30, first put line 30 onto the screen, by saying LIST 30. (Say LIST, not EDIT: your computer doesn't understand the word EDIT.) On your computer, the cursor does not blink: it's a solid square that indicates where you'll be typing. Your computer uses the Catholic method of editing, which uses the Catholic cross and its effect on bodies and souls. Here are the details. . . . Tap the ESC key. A cross will appear in the middle of the cursor. Move the cursor (including its cross) up to the line you want to edit, by pressing the up-arrow key repeatedly. Then tap the ESC key again, to get rid of the cross. (The up-arrow key works only when you see a cross, because, according to Catholics, ``to get to heaven you must follow the Cross''. Most other keys are Temptations: they're effective only when you do not see a cross.) Move the cursor to the part of the line you want to correct, by pressing the right-arrow key repeatedly. Then make your corrections. Replace To replace a character, move the cursor to the character you want to replace, then type the new character you want instead. Delete To delete a group of characters, move the cursor to the first character in the group. Create a cross (by tapping the ESC key), then move the cross across the group of characters (by pressing the right-arrow key), until you've passed the last character in the group. Then get rid of the cross (by tapping the ESC key again). The characters that the cross passed over will go to heaven and disappear from their earthly existence. (Their bodies will remain on the screen, but their souls will departed so the characters won't affect any future LIST.) Insert To insert extra characters, move the cursor to the place where you want the extra characters to begin appearing. Then move the cursor up (by tapping the ESC key, then the up-arrow key, then the ESC key). Type the characters you want to insert. Then create a cross (by tapping the ESC key), and move the cross to where you want the extra characters to begin appearing (by tapping the down-arrow and left-arrow keys). Finally, get rid of the cross. When you finish editing When you've finished correcting the line, press the right-arrow key repeatedly, until you get past the last character in the line. Then press the RETURN key. To see what happened to the line, LIST it. Why bother? Because that Catholic method of editing is so long-winded, most programmers don't bother using it: instead, they type the entire line over! Apple 2e The editing process is the same as for the 2c, with just two exceptions: 1. To begin the whole editing process, tap the ESC key, then the left-arrow key, then move the cursor up to the line you want to edit. 2. You see the cross only if your Apple 2e contains an 80-column card and you previously said PR#3. Otherwise, the cross is invisible: when the cross is at the cursor, the cursor covers up the cross, so that you can't see the cross (even though the cross is there). Apple 2 and 2+ The method of editing is even more complicated, so don't bother! Just type the whole line over again. Spaces after numbers (page 332) Your computer does not automatically put spaces after numbers. Spaces before numbers (page 333) Your computer does not automatically put spaces before positive numbers. For example, if you give this command ___ print "the temperature is";4+25;"degrees" the computer prints: the temperature is29degrees The computer does not automatically put a space before or after the 29. To put spaces near the 29, put spaces in the strings nearby, like this: print "the temperature is ";4+25;" degrees" Multiple calculations (page 333) If you give this command ___ print 6+2;6-2 your computer will print the answer to 6+2 (which is 8) and also print the answer to 6-2 (which is 4), but won't put any spaces between the answers. Your computer will print: 84 To force your computer to put a space between the answers, replace the semicolon by a space in quotation marks, like this: print 6+2" "6-2 That makes your computer print: 8 4 Clear the screen (page 333) Your keyboard lacks a CLEAR key. Instead of pressing a CLEAR key, press the ESC key, then type an @ symbol. (To type the @ symbol, remember to press the SHIFT key.) Your computer doesn't understand the CLS command. Instead of typing CLS, type the word HOME. Print on paper (page 333) Your keyboard doesn't have a PRINT key or ECHO key, and your computer doesn't understand LPRINT or LLIST. To print on paper, here's what to do instead. . . . Make sure the printer is plugged in, turned on, and full of paper. Make sure any lights indicating POWER, READY, SELECT, and ON LINE are glowing. To activate the printer, type this: pr#1 That makes the computer use paper instead of your screen. After you type PR#1, everything you and the computer type will appear on paper instead of on the screen. If you ever want to use your screen again, you must deactivate the printer, by typing: pr#0 For example, to make the computer print just ``I love you'' on paper, you must activate the printer, then tell the computer to print ``I love you'', then deactivate the printer, like this: pr#1 print "I love you" pr#0 If a program prints on the screen but you want it to print on paper instead, activate the printer before you type RUN. Here's how: pr#1 list pr#0 In the middle of your program, one of the lines can say ``pr#1''. But if a line of your program simply says ___ 30 pr#1 the computer will get confused. Instead, say: 30 d$=chr$(4) 31 ?d$"pr#1" To make line 60 deactivate the printer, say: 60 ?d$"pr#0" For example, this program prints two poems. It prints ``love is like a dove'' on your screen, and prints ``life is full of strife'' on paper: new 10 print "love" 20 print "is like a dove" 30 d$=chr$(4) 31 ?d$"pr#1" 40 print "life" 50 print "is full of strife" 60 ?d$"pr#0" run GO TO (page 334) To abort a program, hold down the CONTROL key; and while you keep holding down the CONTROL key, tap the C key. If the computer is printing on the screen faster than you can read, you can make the computer slow down. To slow the printing, type this command: speed=0 For example, to make the computer LIST your program slowly, and also PRINT slowly when it runs your program, type this: speed=0 list run To make the computer print quickly again, at full speed, type this command: speed=255 SPEED=0 means slow; SPEED=255 means fast. For an intermediate speed, pick a number between 0 and 255. Save on disk (page 336) If you buy a blank disk and want your computer to use it, you must turn the blank disk into an Apple disk. To do that, turn the computer off, make sure the built-in drive contains the ``Systems Utilities ProDOS disk'', close the door, then turn the computer back on. The screen will eventually show you the main menu, which looks like this: 1. Copy files 2. Delete files 3. Rename files 4. Lock/unlock files 5. Duplicate a disk 6. Format a disk 7. Identify and catalog a disk 8. Advanced operations 9. Exit system utilities Tap the 6 key, then tap the RETURN key four times. The computer will say: Place the disk you wish to format in the built-in drive. Press RETURN to continue. Obey the computer: put the blank disk into the built-in drive, then press the RETURN key. The computer will grunt several times loudly: hold your ears! 20 seconds later, the computer will say: Format complete. Press RETURN to continue, ESC to return to the main menu. The blank disk has been turned into an Apple disk. Press the ESC key. You'll see the main menu again. Tap the 9 key, then tap the RETURN key twice. Then tap the ESC key, followed by the 4 key (for fat characters) or the 8 key (for thin characters). You cannot copy a program onto the System Utilities ProDOS disk. Instead, copy your program onto a blank disk that you turned into an Apple disk. Omit quotation marks. Most computers: SAVE "JOE" Your computer: save joe Instead of saying FILES, say CATALOG or CAT. If you say CAT, the computer will print an abridged catalog. How to use drive 2 The built-in drive is called drive 1. If you buy an extra drive, the extra is called the external drive; it's also called drive 2. Normally, the computer uses drive 1. If you want it to use drive 2 instead, put a comma and a D2 at the end of the disk command. For example, to get a catalog of drive 2, say: catalog,d2 To save JOE in drive 2, say: save joe,d2 If you put a comma and D2 at the end of a command, the Apple assumes you're more interested in drive 2 than in drive 1. Therefore, it will automatically use drive 2 instead of drive 1 for all future commands. If you ever want to use drive 1 again, you must give a command that ends in a comma and D1. How to copy an entire disk To copy an entire disk, put the System Utilities ProDOS disk into the built-in drive. Turn the computer off, then on again. When you see the main menu, tap the 5 key, then tap the RETURN key three times. The computer will say: Place the source disk in the built-in drive. Press RETURN to continue. Obey the computer: into the built-in drive, put the disk you want to copy; then press the RETURN key. The computer will say: Place the destination disk into the built-in drive. Press RETURN to continue. Obey the computer: into the built-in drive, put a blank disk; then press the RETURN key twice. The computer will turn the blank disk into an Apple disk. Then it will say, ``Place the source disk into the built-in drive.'' Into the built-in drive, put the disk you want to copy; then press the RETURN key. Then it will say, ``Place the destination disk into the built-in drive.'' Grab the blank disk that you had just turned into an Apple disk, and put it into the built-in drive; then press the RETURN key. Seven more times, the computer will tell you to place the source disk and then the destination disk into the built-in drive. Obey the computer: swap the disks seven more pairs of times, and press the RETURN key after each time. Finally, the computer will say: Disk copy complete. Press RETURN to continue, ESC to return to the main menu. Press the ESC key. You'll see the main menu. Tap the 9 key, then the RETURN key twice, then say how wide you want the characters to be (by tapping ESC then 4, or ESC then 8). How to create a quick-start disk To create a quick-start disk (which helps start using BASIC faster), get a blank disk, and turn it into an Apple disk (by using the System Utilities ProDOS disk). Then get the main menu on the screen again, and make sure the System Utilities ProDOS disk is in the main drive. With the main menu still on the screen, tap the 1 key, tap the RETURN key four times, tap the down-arrow key six times, tap the right-arrow key, tap the down-arrow key again, tap the right-arrow key again, and tap the RETURN key. The computer will say: Place the destination disk in the built-in drive. Press RETURN to continue. Obey the computer: put the blank Apple disk into the built-in drive, then press the RETURN key. The computer will tell you to swap disks four more times. Finally, the computer will say: Copying complete. Press RETURN to continue, ESC to return to the main menu. Press the ESC key. You'll see the main menu. Tap the 9 key, then the RETURN key twice, then say how wide you want the characters to be (by tapping ESC then 4, or ESC then 8). You've created a quick-start disk. In the future, whenever you want to start using the computer quickly, put the quick-start disk into the drive (instead of the System Utilities ProDOS disk), and then turn on the computer. The computer will say: PRODOS BASIC ] Then just say how wide you want the characters to be (by tapping ESC then 4, or ESC then 8). If you save a program on that disk, and call the program STARTUP (instead of JOE), the computer will automatically run that program whenever you start up the computer. If you make the top two lines of that program say ___ 10 d$=chr$(4) 11 ?d$"pr#3" the computer will automatically tap the ESC key and 8 key for you. Apple 2e To turn a blank disk into an Apple disk, turn the computer off, make sure drive 1 contains the ProDOS User's Disk, close the door, and turn the computer back on. The computer will say PRODOS USER'S DISK. Tap the F key; the computer will say FILER. Tap the V key; the computer will say VOLUME COMMANDS. Tap the F key; put the blank disk into drive 1; press the RETURN key three times; the computer will say FORMATTING. 25 seconds later, the computer will say FORMAT COMPLETE; the blank disk has been turned into an Apple disk. Press the ESC key twice, then the Q key, then the RETURN key. To copy an entire disk, put the ProDOS User's Disk into drive 1. Turn the computer off, then on again. The computer will say PRODOS USER'S DISK. Tap the F key; the top of the screen will say FILER. Tap the V key; the top of the screen will say VOLUME COMMANDS. Tap the C key; grab the disk you want to copy, and put it in drive 1; put a blank disk in drive 2; press the RETURN key six times. When the computer finishes copying, press the ESC key twice, then the Q key, then the RETURN key. Apple 2 and 2+ To turn a blank disk into an Apple disk, put the blank disk into drive 1 and then type: NEW 10 PRINT "HELLO" INIT HELLO The drive's red light will glow for about 30 seconds. When it stops glowing, your blank disk is finally an Apple disk; it's called a ``slave of a DOS 3.3 System Master''. It's also a quick-start disk. Your computer doesn't understand CAT: say CATALOG. To copy an entire disk, put the DOS 3.3 System Master disk into drive 1. Type RUN COPYA and press the RETURN key. The computer will say APPLE DISKETTE DUPLICATION PROGRAM. Grab the disk you want to copy, and put it in drive 1; put a blank disk in drive 2; press the RETURN key five times. The computer will copy all information from drive 1's disk to the blank disk. (In the process, it will also turn the blank disk into an Apple disk.) Then the computer will ask DO YOU WANT TO MAKE ANOTHER COPY? If you don't, type an N and then press the RETURN key. How to choose a name (page 337) Your program's name can be short (such as JOE) or long: up to 15 characters. The name's first character must be a letter; the remaining characters must be letters, digits, or periods. Load from disk (page 337) Omit quotation marks. Most computersYour computer LOAD "JOE" load joe RUN "JOE" run joe Edit the disk (page 337) Instead of saying RENAME ``JOE'' TO ``FRED'', say: rename joe,fred Space on the disk (page 337) To erase JOE from the disk, instead of saying KILL ``JOE'' say: delete joe Tapes (page 337) The Apple 2c can't handle tapes. Long variable names (page 340) Variable names must be short. The name of a numeric variable must be just 1 or 2 characters; the name of a string variable must be just 1 or 2 characters followed by a dollar sign. If you try to make the variable's name longer than that, the computer will handle it unreliably. If you want a variable name that's 2 characters long, avoid the following 2-character names, which have special meanings: TO, IF, ON, FN, GR, AT, OR. INPUT (page 341) In the INPUT statement, the computer's question is called the prompt. The prompt begins and ends with a quotation mark. On your computer, the prompt should end with a question mark then a space then a quotation mark. . . . Most computers: 10 INPUT "WHAT IS YOUR NAME";N$ Your computer: 10 input "What is your name? ";n$ Usually, you can abort a program by tapping the C key while holding down the CONTROL key. But while the computer is doing an INPUT statement, that method won't work, unless you press the RETURN key afterwards. Fancy relations (page 349) Your computer can't handle the letter A followed by the word THEN. For example, it can't handle: if x=a then print "wow" To prevent the letter A from being next to THEN, reverse the equality ___ if a=x then print "wow" or use parentheses to separate the A from the THEN: if (x=a) then print "wow" ELSE (page 349) Your computer doesn't understand the word ELSE. FOR . . . NEXT (page 355) If you indent the lines between FOR and NEXT, your computer ignores the indentation. When you LIST your program, you won't see any indentation. So don't bother to indent. Renumbering (page 367) Your computer doesn't understand RENUM. The PAUSE key (page 367) Your keyboard lacks a PAUSE key. To make the computer pause, hold down the CONTROL key; and while you keep holding down the CONTROL key, tap the S key. To stop pausing, press the SPACE bar. Apostrophe (page 367) Instead of an apostrophe, type a colon followed by the word REM (which stands for ``remark''). For example: 40 c=40: rem because Russ has 40 computers Zones (page 368) If you chose 80 characters per line (by tapping ESC and then 8), your screen has 5 zones, and each zone is 16 characters wide. If you chose 40 characters per line (by tapping ESC and then 4), your screen has just 3 zones. The left zone is 16 characters wide; the middle zone is also 16 characters wide; the right zone is just 8 characters wide. LOCATE (page 371) Your computer doesn't understand the word LOCATE. To print ``DROWN'' beginning at line 3's 7th position, say this: vtab 3: htab 7: print "DROWN" Pixels (page 372) Apple handles pixels differently from most other computers. Here are the details. . . . Simple graphics To use simple, low-resolution graphics, type: gr That makes the computer split the screen into two parts. The top part of your screen will be used for graphics. The bottom of your screen will not be used for graphics: instead, it will be used for non-graphics (which Apple calls ``text''). When you type GR, the computer makes the top part of your screen (the graphics part) be entirely black. Your next step is to choose a color to draw in. You can choose these colors: 0. black 1. magenta (purplish red) 2. dark blue 3. lavender (light purple) 4. dark green 5. gray 6. blue (light greenish blue) 7. light blue 8. brown 9. orange 10. gray 11. pink 12. green 13. yellow 14. aqua (light greenish blue) 15. white You must also choose which pixel you want to color: the pixel's X and Y coordinates must each be from 0 to 39. For example, to make pixel (31,37) become pink, type this: color=11: plot 31,37 To make pixel (5,9) and pixel (17,21) both become yellow, type this: color=13: plot 5,9: plot 17,21 If the colors on your TV look wrong, adjust your TV's COLOR and TINT dials. To draw a green horizontal line from pixel (4,19) to pixel (8,19), type this: color=12: hlin 4,8 at 19 To draw a blue vertical line from pixel (4,20) to pixel (4,30), type this: color=6: vlin 20,30 at 4 To print ``welcome to the art museum'' on the bottom part of the screen (which is for non-graphics), just say: print "welcome to the art museum" Whenever you want to stop using graphics, type: text: home That tells the computer to use the entire screen for non-graphics (TEXT). You can put all those ideas into a program, like this: 10 home: gr 20 color=11: plot 31,37 30 color=13: plot 5,9: plot 17,21 40 color=12: hlin 4,8 at 19 50 color=6: vlin 20,30 at 4 60 print "welcome to the art museum" 70 for i = 1 TO 4000: next 80 text: home Line 10 includes the word HOME, to make sure that the bottom part of the screen (for non-graphics) begins entirely black. Lines 20-50 draw a picture. Line 60 prints a caption. Line 70 makes the computer count to 4000: while the computer counts, you can admire the picture that the computer drew; if you want to admire the picture longer, change the 4000 to 10000. Line 80 returns the computer to its normal state, which is non-graphics. In that program, lines 10, 70, and 80 are particularly important. Every low-resolution graphics program should begin by saying ``HOME: GR'', and should end by saying ``FOR I'' and ``TEXT: HOME''. High-resolution graphics High-resolution graphics differs from low-resolution graphics in the following ways . . . For low-res, you say ``GR''. For high-res, you say ``HGR: VTAB 21''. for low-res, you say ``COLOR='' and choose a color from 0 to 15. For high-res, you say ``HCOLOR='' and choose one of these high-res colors: 0. black 1. usually green; blackif X is even;white if adjacent pixel isn't black 2. usually purple; blackif X is odd;white if adjacent pixel isn't black 3. usually white; greenif X is oddand adjacent pixel is black; purpleif X is evenand adjacent pixel is black 4. black 5. usually orange; blackif X is even;white if adjacent pixel isn't black 6. usually blue; blackif X is odd;white if adjacent pixel isn't black 7. usually white; orangeif X is oddand adjacent pixel is black; blueif X is evenand adjacent pixel is black For low-res, you say ``PLOT''. For high-res, you say ``HPLOT''. For low-res, the X coordinate and Y coordinate each go from 0 to 39. For high-res, the X coordinate goes from 0 to 279, and the Y coordinate goes from 0 to 159. For low-res, you say ``HLIN'' to draw a horizontal line, and you say ``VLIN'' to draw a vertical line. For high-res, you can draw a line in any direction, by saying ``HPLOT TO''. For example, if you say ___ hplot 250,140 hplot to 70.90 hplot to 180,114 the computer will plot the pixel (250,140), then draw a diagonal line from there to pixel (70,90), then draw a diagonal line from pixel (70,90) to pixel (180,114). You can combine those commands into a single command: hplot 250,140 to 70,90 to 180,114 Here's a complete program: Use high-res. 10 home: hgr: vtab 21 Draw green lines. 20 hcolor=1: hplot 250,140 to 70,90 to 180,114 Write a caption. 30 print "welcome to the art museum" Pause. 40 for i = 1 to 4000: next End the graphics. 50 text: home Advanced commands (and page #) BEEP (page 373). Instead of saying BEEP, say: print chr$(7); SOUND (373). Your computer doesn't understand the word SOUND. PLAY (374). Your computer doesn't understand the word PLAY. PRINT USING (374). Your computer doesn't understand PRINT USING. Exponents (384). Your computer makes a mistake when handling exponents. According to mathematicians and most other computers, -52 means ``the negative of 52''; so it's -25. But the Apple makes the mistake of thinking that -52 means ``the square of -5'', which is 25. If you say PRINT -5^2, the Apple will therefore print 25, which mathematicians consider to be wrong. For another example, suppose you say: 10 x=5 20 print -x^2 The Apple mistakenly thinks that line 20 means ``the square of -X'', and therefore prints 25. (According to mathematicians and other computers, line 20 means ``the negative of X2'', and so the answer ought to be -25.) The Apple's mistake makes the Apple incorrectly handle several branches of mathematics. For example, the Apple incorrectly solves quadratic equations and incorrectly graphs upside-down parabolas ___ unless you help your Apple by typing parentheses. To help your Apple, type parentheses whenever a minus sign is followed by an exponentiated number: print -(5^2) Another example: 10 x=5 20 print -(x^2) Those parentheses make the Apple print the correct answer, which is -25. Random integers (388). Omit the word RANDOMIZE. To get a random integer from 1 to 5, instead of saying RND(5), say 1+INT(RND(1)*5). Random decimals (391). For a random decimal between 0 and 1, say RND(1) instead of just RND. Left, right, middle (394). Your computer doesn't understand an equal sign after MID$. Searching in a string (395). Your computer doesn't understand INSTR. Clock (395). Your computer doesn't have a clock, and so it doesn't understand TIME$, TIMER, or DATE$. String-number conversion (395). Your computer makes STR$(81.4) be the string ``81.4'', without a blank space. Repeating characters (395). Your computer doesn't understand STRING$. Types of numbers (397). You can't use double-precision. To create a real number, you can type as many digits as you wish, but the computer remembers just the first 10 digits accurately, and prints just the first 9 of them on your screen. RAM consumption (397). Each real number consumes 5 bytes of RAM. Variables (397). For integer variables, you can use the symbol % but not the word DEFINT. Adjacent printing (407). You can't put a semicolon immediately after INPUT. LINE INPUT (407). You can't say LINE INPUT. INPUT$ (407). Instead of saying A$=INPUT$(1), say GET A$. Instead of saying ___ 6 P$=INPUT$(4) say: 6 get p1$: get p2$: get p3$: get p4$: p$=p1$+p2$+p3$+p4$ Joystick (408). Say PDL instead of STICK. If you say PDL and then suddenly say PDL again, the computer won't compute the second PDL accurately. To improve the accuracy, make the computer pause before the second PDL, by inserting a FOR . . . NEXT loop: 100 x=pdl(0): for i = 1 TO 100: next: y=pdl(1) Mouse (408). Your computer's version of BASIC is not designed to work with a mouse. SWAP (409). Your computer doesn't understand SWAP, so use the alternative. ON ERROR GO TO (414). Change ERROR to ERR, and change ``ON ERROR GO TO 0'' to ``POKE 216,0''. You can say RESUME, but you cannot put a number or word after RESUME. You cannot say RESUME 30; you cannot say RESUME NEXT. Instead of saying RESUME 30, say ``CALL 62248: GO TO 30''. POKE (414). Normally, the computer uses the whole screen. If you say ___ poke 33,20 the computer will use just the left part of the screen. That part will be 20 characters wide. Whenever you try to type more than 20 characters on a line, the computer will put the excess characters underneath, as part of the line below. The rightmost part of the screen will be unused, and will act as a very wide right margin. If you don't like a width of 20, choose a different width instead. Problem: write a program that puts instructions on the screen and keeps the instructions there permanently, while the rest of the screen changes. Solution: turn on the computer, avoid saying POKE, write the instructions on the rightmost part of the screen (by giving ordinary PRINT statements with TAB or HTAB), and then say ``POKE 33,20''. That POKE prevents the computer from typing anything new on the rightmost part of the screen ___ but the instructions you typed there previously will remain. Apple's LIST command is peculiar. To edit your program more easily, instead of saying just LIST, say: poke 33,33 list That makes the LIST be just 33 characters wide. That particular width ___ 3 characters ___ makes the LIST easier to edit. OPEN FOR OUTPUT (415). This program prints ``eat'' and 4 and ``eggs'' onto a disk file called SUE: 5 d$=chr$(4): ?d$"open sue": ?d$"write sue" 10 print "eat" 20 print 2+2 30 print "eggs" 40 ?d$"close" OPEN FOR INPUT (415). This program makes the computer read SUE and copy it to your screen: 5 d$=chr$(4): ?d$"open sue": ?d$"read sue" 10 input a$ 11 print a$ 20 input b 21 print b 30 input c$ 31 print c$ 40 ?d$"close" OPEN FOR APPEND (415). This program makes the computer append ``good morning!'' to the end of SUE: 10 d$=chr$(4): ?d$"open sue": ?d$"append sue" 20 print "good morning!" 30 ?d$"close" Loops (416). Your computer doesn't understand EOF(1). Instead of saying IF EOF(1) THEN GO TO 1000, put this line at the top of your program: ON ERR GO TO 1000. LOF (416). Your computer doesn't understand LOF(1). PUT (417). This program creates a random-access file called JIM whose record length is 21, and defines JIM's 7th, 9th, and 4th items: 5 d$=chr$(4): ?d$"open jim,l21" 10 ?d$"write jim,r" 7: print "love makes me giggle" 20 ?d$"write jim,r" 9: print "please hold my hand" 30 ?d$"write jim,r" 4: print "I love Lucy" 40 ?d$"close" At the end of line 5, the L21 means Length 21. ``LOVE MAKES ME GIGGLE'' contains 20 characters but requires a record length of 21, because the RETURN key at the end of GIGGLE consumes 1 byte. GET (417). This program makes the computer tell you JIM's 7th item: 5 d$=chr$(4): ?d$"open jim,l21" 10 ?d$"read jim,r" 7: input x$: print x$ 20 ?d$"close" LOC (417). Your computer doesn't understand LOC. Numerical data (417). The computer lets you put numbers in the file. You do not have to convert the numbers to strings. COMMODORE Here's how to use BASIC on the Commodore 64 computer. (The Commodore 64C and SX-64 are similar.) I'll explain how the Commodore 128, 128D, 16, Plus 4, Pet, Super Pet, CBM, and Vic-20 differ. The Amiga resembles the Apple Mac (explained on page 427). The keyboard (page 324) On the Commodore 64, the keys are placed like this: ÚÄÄÄÄÄÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ ÄÄÄÄÂÄÄÄÄ¿ÚÄÄÄ¿ ³ ³ ! ³ " ³ # ³ $ ³ % ³ & ³ ' ³ ( ³ ) ³ ³ ³ ³ ³Clr ³Inst³³F2 ³ ³  ³ 1 ³ 2 ³ 3 ³ 4 ³ 5 ³ 6 ³ 7 ³ 8 ³ 9 ³ 0 ³ + ³ - ³ œ ³Home³Del ³³F1 ³ ÃÄÄÄÄÄÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁ ÄÂÄÄÁÄÄÄÄ´ÃÄÄÄ´ ³ ³ Q ³ W ³ E ³ R ³ T ³ Y ³ U ³ I ³ O ³ P ³ ³ ³ ³ ³³F4 ³ ³ Ctrl ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ @ ³ * ³  ³Restore³³F3 ³ ÚÄÄÁÄÂÄÄÄÄÄÄÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄ ÄÁÄÄÄÄÂÄÄÙÃÄÄÄ´ ³Run ³ ³ A ³ S ³ D ³ F ³ G ³ H ³ J ³ K ³ L ³ [ ³ ] ³ ³ ³ ³F6 ³ ³Stop³ShiftLock³ ³ ³ ³ ³ ³ ³ ³ ³ ³ : ³ ; ³ = ³Return ³ ³F5 ³ ÃÄÄÄÄÁÄÄÄÄÂÄÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÄÄÅÄ ÄÄÂÄÄÄ´ ÃÄÄÄ´ ³ ³ ³ Z ³ X ³ C ³ V ³ B ³ N ³ M ³ < ³ > ³ ? ³ ³  ³  ³ ³F8 ³ ³Commodore³Shift ³ ³ ³ ³ ³ ³ ³ ³ , ³ . ³ / ³Shift³  ³ þ ³ ³F7 ³ ÀÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÁÂÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÂÄÄÁÄÄÄÄÄÁÄ ÄÄÁÄÄÄÙ ÀÄÄÄÙ ³ ³ ³ Space ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ The key in the bottom left corner is called the Commodore key. In the diagram, I wrote the word ``Commodore'' on that key; but if you look at your actual Commodore 64 keyboard, you'll see a fancy C on that key instead. The zero key is Swedish. The computer capitalizes all letters automatically; so to type a capital letter, do not press the SHIFT key. There is no CAPS key. The BACKSPACE key is marked DEL (which stands for DELETE). So to backspace, make sure you hit the DEL key. Do not hit the keys that show left-arrows; the left arrow keys do not backspace correctly. The ENTER key says RETURN on it. Get started (page 325) The computer's power switch is on the computer's right side. Flip that switch ON. Then turn on the TV or monitor. If you're using a TV, turn it to channel 3 or 4. To switch the computer from channel 3 to channel 4 or back to channel 3, flip the computer's channel-selection switch, which is on the back of the computer. If the writing on the TV looks fuzzy, adjust the TV's fine tuning. Adjust the screen's brightness and contrast. When the computer's on and functioning correctly, the computer will say READY (instead of OK). Commodore 128 and 128D Those computers resemble a Commodore Plus 4 until you say ___ GO 64 which makes them imitate a Commodore 64 instead. Math (page 326) To type a plus sign, do not press the SHIFT key. (If you accidentally press the SHIFT key, you'll be typing a crucifix instead of a plus sign.) Long commands on small screens (page 328) A command can contain up to 80 characters. If you try to type more than 80 characters in a command, the computer will ignore the extra characters. Colons (page 329) Although you can put several statements on the same line, the total number of characters in the line must not be greater than 80. Ranges of lines (page 332) Your computer does not understand the word DELETE. To delete lines 30, 31, 32, 33, and 34, you cannot type DELETE 30-34; instead, you must type: 30 31 32 33 34 Arrow keys (page 332) To edit line 30, first put line 30 onto the screen, by saying LIST 30. (Say LIST, not EDIT: your computer doesn't understand the word EDIT.) At the keyboard's lower-right corner, you'll see a pair of arrow keys. By pressing them with or without the SHIFT key, you can move the cursor in all four directions. Move the cursor to the part of line 30 you want to correct, then make your corrections. To delete a character, move the cursor just past that character, then press the DELETE key. The DELETE key deletes the character to the left of the cursor. To replace a character, move the cursor to the character you want to replace, then type the new character you want instead. To insert an extra character in the middle of the line, move the cursor to where you want that character to appear, then tap the INST key while holding down the SHIFT key, then type the character you want to insert. (To insert two characters, you must tap the INST key with SHIFT, then type the first character, then tap the INST key with SHIFT again, then type the second character.) When you've finished correcting the line, press the RETURN key, which tells the computer to take the corrections seriously. After pressing the RETURN key, you might like to move the cursor to the bottom of the screen. If you'd like to do that, press the down-arrow key several times. Hassle That editing procedure is easy, except for one hassle: under certain unusual conditions, the cursor keys and INST/DEL key don't work! Under those conditions, the cursor keys and INST/DEL keys print strange symbols on your screen instead of moving the cursor. If that happens to you, press the RETURN key and then try again to edit the line. If it happens again, press the RETURN key, then move the cursor to the bottom of the screen, and type the whole line over again. I said the hassle occurs ``under certain unusual conditions''. Specifically, it occurs only if you begin an editing sequence (by pressing the cursor keys and INST/DEL key) when you're at the right-hand part of a line: the part that's to the right of an unmatched quotation mark or to the right of an inserted space (inserted by the INST key). Clear the screen (page 333) The CLEAR key is marked ``CLR HOME''. To clear the screen, hold down the SHIFT key; and while you keep holding down the SHIFT key, press the ``CLR HOME'' key. Your computer does not understand CLS. To make line 10 clear the screen, type this instead: 10 PRINT ""; To make that heart, hold down the SHIFT key with the CLR HOME key. Print on paper (page 333) Your keyboard doesn't have a PRINT key or ECHO key, and your computer doesn't understand LPRINT or LLIST. To print on paper, here's what to do instead. . . . Make sure the printer is plugged in, turned on, and full of paper. Make sure any lights indicating POWER, READY, SELECT, and ON LINE are glowing. To activate the printer, type this: OPEN 4,4: CMD 4 That makes the computer use paper instead of your screen. Henceforth, the computer will print all its answers on paper instead of on your screen. If you ever want the computer to print on your screen again, you must deactivate the printer, by typing: PRINT#4: CLOSE 4 For example, to make the computer print just ``I LOVE YOU'' on paper, you must activate the printer, then tell the computer to print ``I LOVE YOU'', then deactivate the printer, like this: OPEN 4,4: CMD 4 PRINT "I LOVE YOU" PRINT#4: CLOSE 4 If a program prints on the screen but you want it to print on paper instead, activate the printer before you type RUN. Here's how: OPEN 4,4: CMD 4 RUN PRINT#4: CLOSE 4 Here's a fancy program that prints two poems. It prints ``LOVE IS LIKE A DOVE'' on your screen, and prints ``LIFE IS FULL OF STRIFE'' on paper: NEW 10 PRINT "LOVE" 20 PRINT "IS LIKE A DOVE" 30 OPEN 4,4: CMD 4 40 PRINT "LIFE" 50 PRINT "IS FULL OF STRIFE" 60 PRINT#4: CLOSE 4 RUN To LIST your program on paper instead of on your screen, type this: OPEN 4,4: CMD 4 LIST PRINT#4: CLOSE 4 GO TO (page 334) The BREAK key is marked ``RUN STOP''. So to abort a program, press the ``RUN STOP'' key. If the computer is printing on the screen too quickly for you read, you can make the computer print more slowly. To slow the printing, hold down the CTRL key while the computer prints. The computer will print slowly, as long as you keep holding down the CTRL key. When you lift your finger from that key, the computer will print quickly again. Save on disk (page 336) When you flip the disk drive's power switch, you create an electrical surge that damages any disk inside the drive. So before flipping the drive's power switch, make sure the drive is empty. So to turn on your computer system, first remove any disk from the drive; then flip on the drive's switch; then turn on the computer. Memorize that sequence: ``disks out, drive on, computer on.'' When you're done using the computer, follow this sequence: ``disks out, computer off, drive off''. How to insert a disk To put a disk into the drive, first make sure the disk drive's red light is off. Then open the drive's door. Insert the disk into the drive. When you insert it, make sure the disk's label is on top of the disk, and make sure the disk's big oval cutout goes into the drive before the label does. Close the drive's door. How to turn a blank disk into a Commodore disk If you buy a blank disk and want your computer to use it, you must turn the blank disk into a Commodore disk. To do that, insert the blank disk into the drive (and close the door). To name the disk ELIZABETH and give it ID number 00, type this: OPEN 15,8,15,"N:ELIZABETH,00" CLOSE 15 Each disk you create must have a different ID number. The ID number can be any number from 00 to 99 ___ or it can even be a pair of letters. The drive's red light will glow for about 2 minutes. When the light stops glowing, your blank disk is finally a Commodore disk. SAVE Instead of saying SAVE ``JOE'', say: SAVE "JOE",8 FILES Instead of saying FILES, say: LOAD "$",8 LIST Watch the red light Whenever you give a disk command, the computer sends the command to the disk drive and immediately says READY. The word READY does not mean the drive's finished the command yet. The drive doesn't finish the command until the drive's red light stops glowing. If you give a wrong disk command, the computer nevertheless sends it to the drive and says READY. But when the drive receives that command, the drive gripes by blinking its red light repeatedly. So a repeatedly blinking light means you made an error. A continually glowing light means your command is okay and the drive is obeying it. Here's the rule: ``Blink is bad. Glow is good.'' If you give a bad command and the light starts to blink, you must stop the blinking, by typing this: OPEN 15,8,15,"I" CLOSE 15 Commodore 16, Plus 4, Pet, Super Pet, and CBM Turn a blank disk into a Commodore disk by saying HEADER ``ELIZABETH'',I00,D0. Save JOE by saying DSAVE ``JOE''. List the files on the disk by saying DIRECTORY (if you have a Commodore 16 or Plus 4) or CATALOG D0 (if you have a Pet, Super Pet, or CBM). How to choose a name (page 337) Your program's name can be short (such as JOE) or long: up to 16 characters. Load from disk (page 337) Instead of saying LOAD ``JOE'', say this: LOAD "JOE",8 Instead of saying RUN ``JOE'', say this: LOAD "JOE",8 RUN Commodore 16, Plus 4, Pet, Super Pet, and CBM Say DLOAD ``JOE'' instead of LOAD ``JOE'',8. Edit the disk (page 337) If you try to copy JOE onto a disk (by saying SAVE ``JOE'',8) and the disk already contains a program named JOE, the drive will gripe, by blinking its light. To avoid such griping, give this command instead: SAVE "@:JOE",8 In that command, the at-sign followed by the colon tells the drive: save JOE, even though the disk already contains a JOE. Instead of saying RENAME ``JOE'' TO ``FRED'', say: OPEN 15,8,15,"R:FRED=JOE" CLOSE 15 Commodore 16, Plus 4, Pet, Super Pet, and CBM You can say RENAME ``JOE'' TO ``FRED''. Space on the disk (page 337) Instead of saying KILL ``JOE'', say: OPEN 15,8,15,"S:JOE" CLOSE 15 Commodore 16, Plus 4, Pet, Super Pet, and CBM Say SCRATCH ``JOE'' instead. Tapes (page 337) To copy a program onto a tape, position the tape and notice the counter's number. Then type the word SAVE. At the end of that word, press the RETURN key. Your computer will say: PRESS RECORD & PLAY ON TAPE Obey the computer: press the recorder's RECORD and PLAY buttons at the same time as each other. The computer will say: OK SAVING READY. Then press the recorder's STOP button. How to read a program from a tape. Put the tape into the recorder. (To do that, you might have to press the recorder's EJECT button.) By using the REWIND, FAST FORWARD, PLAY, and STOP buttons (and the counter, if you have one), position the tape to the program's beginning (or slightly before). Then type the word LOAD. At the end of that word, press the RETURN key. The computer will say: PRESS PLAY ON TAPE Obey the computer, by pressing the recorder's PLAY button. The computer will say: OK SEARCHING FOUND LOADING READY. Then press the recorder's STOP button. Type the word LIST or RUN; then press the RETURN key. Long variable names (page 340) Variable names must be short. The name of a numeric variable must be just 1 or 2 characters; the name of a string variable must be just 1 or 2 characters followed by a dollar sign. If you try to make the variable's name longer than that, the computer will handle it unreliably. If you want a variable name that's 2 characters long, avoid the following 2-character names, which have special meanings: GO, TO, IF, ON, FN, TI, ST, OR. INPUT (page 341) Usually, you can abort a program by pressing the RUN STOP key. But while the computer is doing an INPUT statement, the RUN STOP key refuses to work, unless you simultaneously hold down the RESTORE key. Test whether your Commodore 64 is old Commodore has sold two versions of the Commodore 64. The old version has trouble handling the INPUT statement; the new version handles the INPUT statement correctly. Commodore switched to the new version around the beginning of 1984. Test whether your Commodore 64 is new or old, by running this program: 10 INPUT "ARE YOU THE HAPPIEST PERSON IN THE WHOLE WORLD";A$ 20 PRINT "YOU SAID ";A$ When you run the program, and the computer asks ``ARE YOU THE HAPPIEST PERSON IN THE WHOLE WORLD'', answer YES. If your Commodore 64 is new and works correctly, it will reply: YOU SAID YES If your Commodore 64 is old, it will say this nonsense instead: YOU SAID ARE YOU THE HAPPIEST PERSON IN THE WHOLE WORLD? YES What to do if your Commodore 64 is old In an INPUT statement, the computer's question is called the prompt. An old Commodore 64 can't correctly handle a prompt longer than 38 characters. For example, this line's prompt's too long for an old Commodore 64: 10 INPUT "ARE YOU THE HAPPIEST PERSON IN THE WHOLE WORLD";A$ To prevent the old Commodore 64 from printing nonsense, shorten the prompt to 38 characters or less, like this: 10 INPUT "ARE YOU THE HAPPIEST PERSON";A$ Better yet, eliminate the prompt altogether and replace it by a PRINT statement, like this: 10 PRINT "ARE YOU THE HAPPIEST PERSON IN THE WHOLE WORLD?" 11 INPUT A$ Many examples in this book contain prompts that are too long for an old Commodore 64 to handle. You must revise the examples or buy a newer computer. Vic-20 If you have a Vic-20 computer, you must keep the INPUT statement's prompt short: no longer than 20 characters. Pet, Super Pet, and CBM The RESTORE key is missing. Instead of holding down the RUN STOP and RESTORE keys simultaneously, tap the RETURN key. Once upon a time (page 342) Reminder: some of the prompts are too long for an old Commodore 64 to handle, so you must revise them. Numeric input (page 344) If your Commodore 64 is old, shorten the prompts to 38 characters or less. If you forget to shorten a prompt, when you run the program and input a number the computer will say: REDO FROM START Abort the program (by holding down the RUN STOP and RESTORE keys simultaneously), then shorten the prompt. Therapist (page 345) If you try to invent your own examples using IF . . . THEN, make sure each line of your program contains no more than 80 characters. You'll be tempted to make some of the IF . . . THEN lines be longer, but longer lines won't work. ELSE (page 349) Your computer doesn't understand the world ELSE. DATA . . . READ (page 350) If you invent your own list of data, remember that each line of your program must be short: no more than 80 characters! FOR . . . NEXT (page 355) If you indent the lines between FOR and NEXT, your computer ignores the indentation. When you LIST your program, you won't see any indentation. So don't bother to indent. Renumbering (page 367) Your computer doesn't understand the word RENUM. The PAUSE key (page 367) Your keyboard lacks a PAUSE key. Instead of pausing, you must either slow the computer down (by holding down the CTRL key) or abort (by pressing the STOP key). After aborting a RUN, you can make the computer continue where it left off, by typing: CONT The word CONT will make the computer continue an aborted RUN, but will not make it continue an aborted LIST. Pet, Super Pet, and CBM The CTRL key is messing. Hold down the RVS key instead. Apostrophe (page 367) Instead of an apostrophe, type a colon followed by the word REM (which stands for ``remark''). For example: 40 C=40: REM BECAUSE RUSS HAS 40 COMPUTERS Zones (page 368) Your screen has 4 zones. Each zone is 10 characters wide, so the entire screen is 40 characters wide. TAB (page 370) On other computers, the leftmost character in the line is said to be at position 1. But on your computer, the leftmost character in the line is said to be at position 0 instead; after position 0 come positions 1, 2, 3, etc. So on your computer, if you say TAB(0), you'll be going to the leftmost position; if you say TAB(1), you will not be going to the leftmost position. LOCATE (page 371) Your computer doesn't understand the word LOCATE. To make your computer move the cursor, use the following trick instead. . . . In the middle of your program, write a PRINT statement that prints a string. (To do that, type a line number, followed by the word PRINT, followed by a quotation mark, followed by a string of characters, followed by another quotation mark.) But while you're in the middle of typing the string of characters, press a cursor-arrow key several times. When you press the cursor key, the cursor will not move immediately; instead, you'll see funny symbols in the middle of the string. Later, when you RUN the program and the computer comes to that PRINT statement and sees those funny symbols, the computer will automatically move the cursor. Here's the rule: while you're typing a string, if you try to move the cursor, the computer won't move the cursor until later when the program is running. So to write a program that moves the cursor, tap the cursor-arrow keys in the middle of a string in a PRINT statement. Pixels (page 372) To make your computer easily handle pixels, you must insert a cartridge called Simon's BASIC, which costs extra. For details about how to use that cartridge, read the manual that comes with the cartridge. Advanced commands (and page #) Sounds (page 373). To make your computer easily produce sounds, you must buy the Simon's BASIC cartridge. For details about how to use that cartridge, read the manual that comes with the cartridge. PRINT USING (374). Your computer doesn't understand PRINT USING. Exponents (384). On the Commodore 64's keyboard, the exponent key is next to the RESTORE key and says ``'' instead of ``^''. Random integers (388). Instead of saying RANDOMIZE, say R=RND(0). To get a random integer from 1 to 5, instead of saying RND(5), say 1+INT(RND(1)*5). Commodore 16, Plus 4, and Pet. Say R=RND(-TI) instead of RANDOMIZE. Random decimals (391). For a random decimal between 0 and 1, say RND(1) instead of just RND. Left, right, middle (394). Your computer doesn't understand an equal sign after MID$. Searching in a string (395). Your computer doesn't understand INSTR. Clock (395). Your computer doesn't understand DATE$. It omits colons from the TIME$; so instead of saying TIME$=``13:45:07'', say TIME$=``124507''. Repeating characters (395). Your computer doesn't understand STRING$. Types of numbers (397). You can't use double-precision. To create a real number, you can type as many digits as you wish, but the computer remembers just the first 10 digits accurately, and prints just the first 9 of them on your screen. RAM consumption (397). Each real number consumes 5 bytes of RAM. Variables (397). For integer variables, you can use the symbol % but not the word DEFINT. Omitting the question mark (406). In the INPUT statement, you can't replace the semicolon by a comma. Adjacent printing (407). You can't put a semicolon immediately after INPUT. LINE INPUT (407). You can't say LINE INPUT. INPUT$ (407). Instead of saying ___ 20 A$=INPUT$(1) say: 20 GET A$: IF A$="" THEN GO TO 20 Instead of saying INPUT$(4), you must GET one character at a time. Joystick (408). To make the computer look at joystick 1, say: 100 J=15-(PEEK(56321) AND 15) If the joystick is pushed forward, J is 1. If the joystick is pulled back, J is 2. If the joystick is pushed to the left, J is 4. If the joystick is pushed to the right, J is 8. Combined motions produce combined numbers. For example, if the joystick is pushed forward and to the left simultaneously, J is 1+4, which is 5. If the joystick is untouched and centered, J is 0. To make the computer look at joystick 2, say: 102 J2=15-(PEEK(56320) AND 15) To see the numbers J and J2 on your screen continually, add these lines: 110 PRINT J,J2 120 GO TO 100 Mouse (408). Your computer doesn't use a mouse. SWAP (409). Your computer doesn't understand SWAP, so use the alternative. ON ERROR GO TO (414). Your computer doesn't understand ON ERROR GO TO. POKE (414). Your computer can display 16 colors, which are numbered as follows: 0=black, 1=white, 2=red, 3=cyan, 4=purple, 5=green, 6=blue, 7=yellow, 8=orange, 9=brown, 10=light brown, 11=dark gray, 12=gray, 13=light green, 14=light blue, 15=light gray. Normally, the characters on the screen are light blue (color 14). To choose a different character color, poke the color number into cell #646. For example, to create white characters, say: POKE 646,1 Normally, the screen's background color is a deep blue (color 6). To choose a different background color, poke the color number into cell #53281. For example, to make the background be red, say: POKE 53281,2 Normally, the border along the screen's edge is light blue (color 14). To choose a different border color, poke the color number into cell #53280. For example, to make the border be green, say: POKE 53280,5 Vic-20. On a Vic-20 computer, colors 9 and 10 are pink, color 11 is light cyan, color 12 is light purple, and color 15 is light yellow. The border color number must be less than 8. To handle the border and background colors, don't use cells 53280 and 53281; instead compute (the color number of the background you want)*16+(the color number of the border you want)+8, then set C equal to that sum and say: POKE 36879,C If you omit the +8 from the formula for C, the characters will be inversed, so that you'll get light characters on a dark background, instead of dark characters on a light background. OPEN FOR OUTPUT (415). This program prints EAT and 4 and EGGS onto a disk file called SUE: 5 OPEN 2,8,2,"SUE,S,W" 10 PRINT#2, "EAT" 20 PRINT#2, 2+2 30 PRINT#2, "EGGS" 40 CLOSE 2 Notice you must say PRINT#2, not PRINT#1. In line 5, the W tells the computer to Write SUE. OPEN FOR INPUT (415). This program makes the computer Read SUE and copy it to your screen: 5 OPEN 2,8,2,"SUE,S,R" 10 INPUT#2, A$ 11 PRINT A$ 20 INPUT#2, B 21 PRINT B 30 INPUT#2, C$ 31 PRINT C$ 40 CLOSE 2 OPEN FOR APPEND (415). This program makes the computer Append ``GOOD MORNING!'' to the end of SUE: 10 OPEN 2,8,2,"SUE,S,A" 20 PRINT#2, "GOOD MORNING!" 30 CLOSE 2 Loops (416). Instead of saying EOF(1), say STAND64=64. LOF (416). Your computer doesn't understand LOF. Multiple files (416). The main file is called #2. The next file is called #3: say OPEN 3,8,3,``TOM,S,W''. You can use #2, #3, #4, etc., up to #14. You cannot use #1. How to CLOSE (416). After each CLOSE, you must put a number that says which file to CLOSE. PUT (417). This program creates a random-access file called JIM whose record length is 20, and defines JIM's 7th, 9th, and 4th records: 5 OPEN 15,8,15: OPEN 2,8,2,"JIM,L,"+CHR$(20) 10 PRINT#15, "P"CHR$(2)CHR$(7)CHR$(0)CHR$(0): PRINT#2, "LOVE MAKES ME GIGGLE"; 20 PRINT#15, "P"CHR$(2)CHR$(9)CHR$(0)CHR$(0): PRINT#2, "PLEA SE HOLD MY HAND"; 30 PRINT#15, "P"CHR$(2)CHR$(4)CHR$(0)CHR$(0): PRINT#2, "I LO VE LUCY"; 40 CLOSE 2: CLOSE 15 GET (417). This program makes the computer tell you JIM's 7th item: 5 OPEN 15,8,15: OPEN 2,8,2,"JIM" 10 PRINT#15, "P"CHR$(2)CHR$(7)CHR$(0)CHR$(0): INPUT#2, X$: P RINT X$ 20 CLOSE 2: CLOSE 15 LOC (417). Your computer doesn't understand LOC. Numerical data (417). The computer lets you put numbers in the file. You do not have to convert the numbers to strings. TANDY MODEL 4 Here's how to use BASIC on Tandy's Radio Shack TRS-80 Model 4 computer. (The Models 4D and 4P are similar.) Microsoft BASIC (page 322) Tandy's Radio Shack TRS-80 Model 4 computer can handle two versions of BASIC. The best version, called Model 4 BASIC, requires a disk called Model 4 TRSDOS and BASIC Interpreter and requires a drive to put it in. The alternative version, called Model 3 BASIC, is only for people who lack a disk drive or lost the disk called ``Model 4 TRSDOS and BASIC Interpreter'' or want to run obsolete ``Model 3'' software. I'll assume you have the disk called ``Model 4 TRSDOS and BASIC Interpreter'' and a drive to put it in, so that you can run Model 4 BASIC. Here's how to use Model 4 BASIC. . . . The keyboard (page 324) The keys are placed like this: ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄ¿ ³ ! ³ " ³ # ³ $ ³ % ³ & ³ ' ³ ( ³ ) ³ ³ * ³ = ³ ³ ³ 1 ³ 2 ³ 3 ³ 4 ³ 5 ³ 6 ³ 7 ³ 8 ³ 9 ³ 0 ³ : ³ - ³Break³ ÀÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÄÄÂÄÙ ³ Q ³ W ³ E ³ R ³ T ³ Y ³ U ³ I ³ O ³ P ³ ` ³Clear³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ @ ³ ³ ÚÄÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÄÄÄÄÄ´ ³ ³ A ³ S ³ D ³ F ³ G ³ H ³ J ³ K ³ L ³ +~³ ñ³ ³Ctrl³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ;^³ Enter _³ ÀÂÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÄÄÄÄÄÅÄ¿ ³ ³ Z ³ X ³ C ³ V ³ B ³ N ³ M ³ <{³ >}³ ?³³ ³ ³ ³Shift³ ³ ³ ³ ³ ³ ³ ³ ,[³ .]³ /\³Shift ³³ ÀÄÄÄÄÄÁÄÄÄÅÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÅÄÄÄÁÂÄÄÄÄÄÅÄÅÄ¿ ³ ³ ³DelLn³ ³ ³ ³ Space ³Caps³  ³³þ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÁÄÄÄÄÄÁÄÁÄÙ Exception: if you bought the computer before 1984, the Ctrl key, CLEAR key, and arrow keys are located differently. The zero key is Swedish. In that diagram, one of the keys looks like this: ÚÄÄÄ¿ ³ <{³ ³ ,[³ ÀÄÄÄÙ If you tap that key, you'll be typing a comma. If you tap that key while holding down the SHIFT key, you'll be typing the symbol ``<''. If you tap that key while holding down the CLEAR key, you'll be typing the symbol ``[''. To type the remaining symbol on that key (the ``{''), do this: hold down the CLEAR key; while you keep holding down the CLEAR key, hold down the SHIFT key; while holding down the CLEAR and SHIFT keys, tap the key that shows the ``{''. The BACKSPACE key has a left-arrow on it; so if you tap the left-arrow key, the computer will erase the last character you typed. If you tap the left-arrow key while holding down the SHIFT key, the computer will erase the entire line you've been typing. Get started (page 325) When you flip the power switch, you create an electrical surge that damages any disks inside the computer. So before flipping the power switch, remove any disks from the computer. Then flip on the computer's power switch, which is underneath the computer's right side. The red light on the bottom disk drive will turn on, then off. Insert a disk that contains ``Model 4 TRSDOS and BASIC Interpreter'' into the bottom drive. When you insert it, make sure the disk's label is on top of the disk, and make sure the disk's big oval cutout goes into the drive before the label does. (The Model 4P is different: the disk drive's slot is vertical instead of horizontal and requires the disk's label to be on the disk's left side.) Close the drive's door. On the far right side of the keyboard, you'll see an orange button. Press it. The computer will say ``Date''. If the writing looks fuzzy, turn the brightness and contrast dials, which are underneath the computer's left side. Type the date. For example, if today is January 24, 1996, type 01/24/96 and then press the ENTER key. The computer will say: TRSDOS Ready Type this word: basic Then press the ENTER key. After a brief pause, the computer will say: Ready Notice that the computer says ``Ready'' instead of ``OK''. Whenever you're done using the computer, remove any disks from the drives, before you flip off the power. What if computer gripes? (page 330) If the computer gripes at you, press the ENTER key immediately. After pressing the ENTER key, correct the error by retyping the line that the computer griped about. Arrow keys (page 332) To edit line 20, type: edit 20 If the first character in line 20 is correct (and doesn't need to be edited), press the SPACE bar. If the second character in line 20 is correct also, press the SPACE bar again. Press the SPACE bar for each correct character. Each time you press the SPACE bar, the character that you said was correct appears on the screen. When you get to the point where the next character on the screen would be incorrect, press the D key instead of the SPACE bar. The D key means: delete the next character. Pressing the D key causes the next character to be surrounded by backslashes, which mean the character is being deleted. To insert extra characters in the line, press the SPACE bar several times, until you get to where you want the characters to be inserted. Then press the I key (which tells the computer you want to insert). Then type the characters you want to insert. After typing them, tap the up-arrow key while holding down the SHIFT key. When you've finished all the deletions and insertions for that line, press the ENTER key. That makes the screen show the remainder of the line (the right-hand part of the line), and tells the computer you've finished editing the line. Clear the screen (page 333) To clear the screen by using the CLEAR key, tap the CLEAR key while holding down the SHIFT key. Print on paper (page 333) Your keyboard lacks a PRINT key. Instead of pressing a PRINT key, tap the colon key (which is next to the zero key) while holding down the CTRL key. Your keyboard lacks an ECHO key. Instead of pressing an ECHO key, type this: system "link *do *pr" To stop the echo, type this: system "reset *do" Save on disk (page 336) If you buy a blank disk and want your computer to use it, you must turn the blank disk into a Radio Shack disk. To do that, put the blank disk into the top drive. Type: system format 1 (q=n) The computer will turn the blank disk into a Radio Shack disk. Then the computer will say ``TRSDOS Ready''. Put Model 4 BASIC onto that disk, by typing: backup :0 :1 The computer will ask whether you're sure; type the letter y. The computer will copy all information from the bottom disk to the top disk. Then the computer will say ``TRSDOS Ready'' again. Tell the computer you want to use BASIC now, by typing: basic The computer will say ``Ready''. FILES Instead of typing the word FILES, type this: system "dir" That makes the computer print a directory, showing the names of all the programs in all your disk drives. How to use drive 1 The main drive is called drive 0. The other drive is called drive 1. Normally, the computer uses drive 0. If you want JOE to be in drive 1 instead of drive 0, put a colon and a 1 after JOE, like this: save "joe:1" How to choose a name (page 337) Your program's name can be short (such as JOE) or long: up to 8 characters. The name's first character must be a letter; the remaining characters should be letters or digits. Tapes (page 337) Model 4 BASIC doesn't use tapes. FOR . . . NEXT (page 355) To indent you can hit the SPACE bar repeatedly. But to indent more easily, hit the right-arrow key once. The PAUSE key (page 367) Your keyboard lacks a PAUSE key. To make the computer pause, tap the @ key while holding down the SHIFT key. (Normally, pressing those keys makes the screen display an accent mark; but if you press those keys while a program is running, the computer will pause instead.) To stop pausing, press the SPACE bar. LOCATE (page 371) Your computer doesn't understand the word LOCATE. Here's what to do instead . . . Your computer considers the screen's top line to be row 0, and the line below it to be row 1. Your computer considers the row's leftmost character to be in column 0, and the next character to be in column 1. To print the word DROWN, so that it begins at row 3 and column 7, type this: print@(3,7), "drown" Pixels (page 372) To make Model 4 BASIC handle pixels, you must buy a graphics board. Read the instructions that come with the board. Advanced commands (and page #) BEEP (page 373). Your computer doesn't understand the word BEEP. SOUND (373). If you type ___ sound 4,10 the computer will produce a sound whose pitch is 4 and whose duration is 10. The pitch can be any integer from 0 to 7: 0=D#, 1=E, 2=F, 3=F#, 4=G, 5=A, 6=A#, 7=B. The duration can be any integer from 0 to 31: 0 means half a second; 31 means about 15 seconds. PLAY (374). Your computer doesn't understand the word PLAY. Exponents (384). To make the symbol ``^'', tap the semicolon key while holding down the CLEAR key. Random integers (388). Say RANDOM instead of RANDOMIZE. Random decimals (391). For a random decimal between 0 and 1, say RND(0) instead of just RND. Clock (395). To set the time to 13:45:07, say SYSTEM ``TIME 13:45:07''. To set the date to 01/24/1996, say SYSTEM ``DATE 01/24/1996''. Your computer doesn't understand TIMER. Joystick versus mouse (408). Your computer doesn't use a joystick or mouse. POKE (414). If you're using TRSDOS version 6.02, cell #2968 normally contains the number 95, which is the ASCII code number for an underline. That makes the cursor's shape be an underline. To change the cursor's shape, POKE a different number into cell #2968. For example, to change the cursor's shape to the letter A (whose ASCII code number is 65), say: poke 2968,65 To create a ``feminist computer'', turn the cursor into a female-sign (whose ASCII code number is 250), by saying: poke 2968,250 Older versions of TRSDOS. Cell #2968 does that only in TRSDOS version 6.2. Instead of cell #2968, version 6.00 uses cell #3040; version 6.01 uses cell #3017. When you turn on the computer, versions 6.00 and 6.01 begin by making the cursor be a double-underline (whose ASCII code is 176) instead of a single-underline. OPEN FOR OUTPUT (415). Instead of saying OPEN ``SUE'' FOR OUTPUT AS 1, say OPEN ``O'',1,``SUE''. In the quotation marks, be sure to put the letter O, not a zero. OPEN FOR INPUT (415). Instead of saying OPEN ``SUE'' FOR INPUT AS 1, say OPEN ``I'',1,``SUE''. OPEN FOR APPEND (415). Instead of saying OPEN ``SUE'' FOR APPEND AS 1, say OPEN ``E'',1,``SUE''. The ``E'' tells the computer to Extend the file. LOF (416). Your computer doesn't understand the usual meaning of LOF(1). PUT (417). Instead of saying OPEN ``JIM'' AS 1 LEN=20, say OPEN ``R'',1,``JIM'',20. End of the file (417). LOF(1) is the number of records in the file (instead of being the number of bytes). TANDY COLOR COMPUTER Here's how to use BASIC on Tandy's Radio Shack TRS-80 Color Computer 2. (The Color Computer 1, Color Computer 3, and Micro Color Computer are similar.) Microsoft BASIC (page 322) When you buy the Color Computer 2, make sure you get extended color BASIC, not standard color BASIC (which costs less but is crummy). The following comments apply to extended color BASIC. The keyboard (page 324) The keys are placed like this: ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄ¿ ³ ! ³ " ³ # ³ $ ³ % ³ & ³ ' ³ ( ³ ) ³Revrs³ * ³ = ³ ³ ³ 1 ³ 2 ³ 3 ³ 4 ³ 5 ³ 6 ³ 7 ³ 8 ³ 9 ³ 0 ³ : ³ - ³Break³ ÚÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÄÄÅÄÄÄÁÄÂÄÁÄÄÄÂÄÁÄ¿ ³ ³ Q ³ W ³ E ³ R ³ T ³ Y ³ U ³ I ³ O ³ P ³Pause³DelLn³ ] ³ ³  ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ @ ³  ³ þ ³ ÀÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÁÂÄÄÄÄÁÄÄÂÄÄÁÄÄÂÙ ³ [ ³ A ³ S ³ D ³ F ³ G ³ H ³ J ³ K ³ L ³ + ³ ³ \ ³ ³  ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ; ³ Enter ³Clear³ ÃÄÄÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÄÄÄÄÁÄÂÄÄÄÙ ³ ³ Z ³ X ³ C ³ V ³ B ³ N ³ M ³ < ³ > ³ ? ³ ³ ³Shift³ ³ ³ ³ ³ ³ ³ ³ , ³ . ³ / ³ Shift ³ ÀÄÄÄÄÄÁÄÄÄÁÄÂÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÅÄÄÄÁÄÄÄÄÄÄÄÙ ³ ³ ³ Space ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ The computer capitalizes all letters automatically; so to type a capital letter, do not press the SHIFT key. There is no CAPS key. The BACKSPACE key has a left-arrow on it; so if you tap the left-arrow key, the computer will erase the last character you typed. If you tap the left-arrow key while holding down the SHIFT key, the computer will erase the entire line you've been typing. Get started (page 325) Attach the computer to a TV. Turn on the computer's power, by pressing the POWER button, which is at the computer's rear. Turn on the TV, and turn it to channel 3 or 4. To switch the computer from channel 3 to channel 4 or back to channel 3, flip your computer's channel-selection switch, which is at the computer's rear. When the computer's on and functioning correctly, the computer will say OK. Ranges of lines (page 332) Say DEL instead of DELETE. Arrow keys (page 332) To edit line 20, type: EDIT 20 If the first character in line 20 is correct (and doesn't need to be edited), press the SPACE bar. If the second character in line 20 is correct also, press the SPACE bar again. Press the SPACE bar for each correct character. Each time you press the SPACE bar, the character that you said was correct appears on the screen. When you get to the point where the next character on the screen would be incorrect, press the D key instead of the SPACE bar. The D key means: delete the next character. Pressing the D key prevents the next character from appearing on the screen. To insert extra characters in the line, press the SPACE bar several times, until you get where you want the characters to be inserted. Then press the I key (which tells the computer you want to insert). Then type the characters you want to insert. After typing them, tap the up-arrow key while holding down the SHIFT key. When you've finished all the deletions and insertions for that line, press the ENTER key. That makes the screen show the remainder of the line (the right-hand part of the line), and tells the computer you've finished editing the line. Print on paper (page 333) Your keyboard doesn't have a PRINT key or an ECHO key. Instead of saying ``LPRINT'' say ``PRINT#-2,''. For example, to print ``I LOVE YOU'' on paper, type this: PRINT #-2, "I LOVE YOU" Even though the computer doesn't understand ``LPRINT'', it does understand ``LLIST''. Save on disk (page 336) When you flip the disk drive's power switch, you create an electrical surge that damages any disk inside the drive. So before flipping the drive's power switch, make sure the drive is empty. When you're done using the computer, remove any disk from the drive, before you flip off the power. How to insert a disk To put a disk into the drive, open the drive's door, then insert the disk into the drive. When you insert it, make sure the disk's label is on top of the disk, and make sure the disk's big oval cutout goes into the drive before the label does. Close the drive's door. (Exception: if your drive was made before 1985, the drive's slit is vertical instead of horizontal, and the disk's label is on the left side of the disk instead of the top.) How to turn a blank disk into a Radio Shack disk If you buy a blank disk and want your computer to use it, you must turn the blank disk into a Radio Shack disk. To do that, insert the blank disk into the drive (and close the door). Then type DSKINI0. (That last character is a zero, not the letter O.) The disk drive's red light will glow for 40 seconds. When the light stops glowing, the computer will say OK. FILES Instead of saying FILES, say DIR (which stands for ``directory''). How to use drive 1 The main drive is called drive 0. If you have an extra drive, that extra is called drive 1. Normally, the computer uses drive 0. If you want JOE to be in drive 1 instead of drive 0, put a colon and a 1 after JOE, like this: SAVE "JOE:1" To make the computer print the names of all the programs in drive 1, type this: DIR 1 How to choose a name (page 337) Your program's name can be short (such as JOE) or long: up to 8 characters. the name's first character must be a letter; the remaining characters should be letters or digits. Edit the disk (page 337) Instead of saying RENAME ``JOE'' to ``FRED'', say RENAME ``JOE/BAS'' to ``FRED/BAS'', to emphasize that JOE was written in BASIC. Space on the disk (page 337) Instead of saying KILL ``JOE'', say KILL ``JOE/BAS''. Tapes (page 337) To copy a program onto a tape, position the tape and notice the counter's number. Then press the recorder's RECORD and PLAY buttons at the same time as each other. Type this: CSAVE "A" The computer will copy the program onto tape and then say OK. Press the recorder's STOP button. How to read a program from a tape Put the tape into the recorder. (To do that, you might have to press the recorder's EJECT button.) Type the word CLOAD. Press the recorder's REWIND button. When the tape is rewound, press the recorder's STOP button. Push the counter's button, so the counter becomes zero. Press the recorder's FAST FORWARD button. Look at the counter. When the number on the counter is almost up to the number of the program's beginning, press the recorder's STOP button. Press the recorder's PLAY button. The computer will search on the tape for the beginning of the program. When the computer reaches the beginning of the program, the computer will print an F. Then the computer begins reading the program. When the computer finishes reading it, the computer will say OK. Press the recorder's STOP button. Type the word LIST or RUN. Long variable names (page 340) Variable names must be short. The name of a numeric variable must be just 1 or 2 characters: the name of a string variable must be just 1 or 2 characters followed by a dollar sign. If you try to make the variable's name longer than that, the computer will handle it unreliably. If you want a variable name that's 2 characters long, avoid the following 2-character names, which have special meanings: GO, TO, IF, ON, FN, OR. INPUT (page 341) For some of the programs that involve string input, the computer will gripe about being ``out of string space''; the computer will say: ?OS ERROR To stop the computer from griping, insert this statement: 1 CLEAR 1000 If the computer still says OS ERROR, raise 1000 to a higher number, like this: 1 CLEAR 2000 Keep raising, until the computer stops that gripe. On the other hand, if you raise too high, the computer will say ___ ?OM ERROR That means you must go lower. So if the computer says ``OS ERROR'', you should raise the CLEAR number; if the computer says ``OM ERROR'', you should lower the CLEAR number. Here's why. . . . Your program contains two kinds of strings: the strings that are known, and the strings that are unknown. For example, if you say ___ 10 G$="DOWN" the G$ is known to be DOWN. If you say ___ 10 INPUT "WHAT IS YOUR NAME";N$ the N$ is unknown, because its value depends on what the human inputs. Normally, the computer reserves enough memory space to hold just 200 unknown characters. If your program needs more characters than that ___ for example, if your program inputs 7 strings, each having 30 characters, so that the total number of characters is 210 ___ the computer will gripe, and say ``out of string space error'' (OS ERROR). If you say ___ 1 CLEAR 1000 the computer will reserve enough space to hold 1000 unknown characters, instead of the normal quantity (which is just 200). How much space can you reserve? That depends on how much memory you bought for your computer. If your computer has little memory, and you try to reserve more space than your computer has, the computer will give up, and say ``out of memory error'' (OM ERROR). FOR . . . NEXT (page 355) If you indent the lines between FOR and NEXT, your computer ignores the indentation. When you LIST your program, you won't see any indentations. So don't bother to indent. The PAUSE key (page 367) To make the computer pause, hold down the SHIFT key; and while you keep holding down the SHIFT key, tap the @ key. To stop pausing, press the SPACE bar. Zones (page 368) Each zone is 16 characters wide. Your screen has just 2 zones, so your screen is 32 characters wide. TAB (page 370) On other computers, the leftmost character in the line is said to be at position 1. But on your computer, the leftmost character in the line is said to be at position 0 instead; after position 0 come positions 1, 2, 3, etc. So on your computer, if you say TAB(0), you'll be going to the leftmost position; if you say TAB(1), you will not be going to the leftmost position. LOCATE (page 371) Your computer doesn't understand the word LOCATE. Here's what to do instead . . . Your computer considers the screen's top line to be row 0, and the line below it to be row 1. Your computer considers the row's leftmost character to be in column 0, and the next character to be in column 1. To print the word DROWN, so that it begins at row 3 and column 7, type this: PRINT@32* 3+7, "DROWN" Pixels (page 372) To use pixels, type these lines: 10 PMODE 4: PCLS: SCREEN 1 10000 GO TO 10000 Line 10 warns the computer that you want to use pixels. (In that line, the PMODE 4 makes the X coordinate go from 0 to 255 and the Y coordinate go from 0 to 191. The PCLS makes the graphic screen begin by being blank. The SCREEN 1 makes the computer show you the graphics instead of text.) Line 10000, at the bottom of your program, makes the computer pause, so that you can admire whatever graphics have been drawn. Between lines 10 and 10000, you can insert lines containing the following commands. . . . To draw a dot at pixel (100,100), say PSET (100,100). To draw a line from pixel (0,0) to pixel (100,100), say LINE (0,0)-(100,100),PSET. To draw a box (``rectangle'') that has a corner at pixel (0,0) and has an opposite corner at pixel (100,100), say LINE (0,0)-100,100),PSET,B. To draw a box that has a corner at (0,0) and an opposite corner at (100,100), and also make the computer fill in the box (i.e., paint the box's interior), say LINE (0,0)-(100,100),PSET,BF. Each of those commands contains the word PSET. To erase the shape that you drew, give the same command again, but replace the PSET by PRESET. To draw a circle centered at pixel (100,100), and to make the circle's radius be 50, say CIRCLE (100,100),50. To erase that circle, say CIRCLE (100,100),50,0. To paint the inside of any shape (such as a circle or a person), say PAINT and mention a point inside the shape. For example, to fill in an outline that has (101,101) inside it, say PAINT (101,101). To erase that paint (and also the shape itself), say PAINT (101,101),0. To erase the entire drawing (``clear the screen''), say PCLS. If you say SCREEN 0, the screen will stop showing graphics (and will show text instead), until you say SCREEN 1 (which brings back the graphics). To get started experimenting with all those commands, run the following program; it draws a line from (0,0) to (100,100) and then draws a circle centered at pixel (100,100) and with radius 50: 10 PMODE 4: PCLS: SCREEN 1 20 LINE (0,0)-(100,100) 30 CIRCLE (100,100),50 10000 GO TO 10000 The computer draws the shapes in green, on a black background. After you've admired the pretty picture, abort the program by pressing the BREAK key. Colors To get colors, line 10 must say PMODE 3 instead of PMODE 4. After you've said PMODE 3, whenever the computer draws (or erases) a pixel, it does the same thing to the pixel next to it. Specifically, if you tell the computer to draw (or erase) a pixel whose X coordinate is even, the computer will do the same thing to the pixel at its right (whose X coordinate is odd). If you tell the computer to draw (or erase) a pixel whose X coordinate is odd, the computer will do the same thing to the pixel at its left (whose X coordinate is even). After you've said PMODE 3, the computer normally draws red shapes on a green background. But if you don't like those colors, you can pick different colors instead. To choose different colors, use these code numbers: 1=green, 2=yellow, 3=blue, and 4=red. For example, to draw yellow shapes on a blue background, say COLOR 2,3. the traditional place to say COLOR 2,3 is in line 10, like this: 10 PMODE 3: COLOR 2,3: PCLS: SCREEN 1 If you prefer, you can say COLOR 2,3 later in your program instead. If you say it later, the shapes at the beginning of your program will be unaffected by that COLOR statement. When you draw new shapes after giving that COLOR statement, the shapes that were already on the screen (in their old colors) remain unchanged; they keep their original colors. When you say PRESET (in the middle of a dot or line or box command), the computer assumes you want the shape erased; to erase the shape, the computer redraws the shape by using the background color. If you recently changed the background color (by saying COLOR), the erasure will be done by using the new background color, which won't match the old background color. If you say CIRCLE (100,100),50,2 the computer will draw the circle in yellow (because the 2 at the end of the CIRCLE command is the code number for yellow). Do not put a 0 at the end of the CIRCLE command, since 0 is not an acceptable color number. You must pick a number from 1 to 4. If you say PAINT, you must say which pixel to start painting at; you must say which color paint to use; and you must remind the computer of what color the outline had that you're filling in. For example, if you want the computer to paint starting at pixel (101,101) ___ which is inside the outline ___ and you want the computer to use yellow paint (whose code number is 2), and the outline that you're filling in was drawn in blue (whose code number is 3), say PAINT (101,101),2,3. Near the end of your program, if you say SCREEN 1,1, you'll see a ``negative'' of your picture. In the ``negative'', green becomes light blue (even though Radio Shack's manual incorrectly says it becomes ``buff''), yellow becomes cyan (greenish blue), blue becomes magenta (purplish red), and red becomes orange. All future drawings (even by other programs) will be done using those ``negative'' colors, unless you tell the computer to return to a ``positive'', by saying SCREEN 1,0. Advanced commands (and page #) BEEP (page 373). Your computer doesn't understand the word BEEP. SOUND (373). If you type ___ SOUND 100,15 the computer will produce a sound whose pitch is 100. You can choose any pitch from 1 to 255. In that example, the 15 makes the computer produce the sound for 1 second. If you want the sound to last longer ___ so that its lasts 2 seconds ___ replace the 15 by 15*2. For 10 seconds, say 15*10. (That's because your computer's metronome beats 15 times per second.) PLAY (374). Your computer handles the PLAY command slightly differently than other computers. Your computer can't play octaves 0 or 6: it plays just octaves 1 through 5. If you don't specify an octave, the computer will play in octave 2. To create a dotted eighth note, put a dot after the 8 instead of after the note's name. For example, to make E be a dotted eighth note, say ``L8.E''. If you say PLAY ``T1'', the computer will play 56 quarter notes per minute, which is very slow (largo). If you say PLAY ``T2'', the computer will play twice as fast: 112 quarter notes per minute (moderato). If you say PLAY ``T3'', the computer will play three times as fast: 168 quarter notes per minute (vivace). You can pick speeds up to PLAY ``T255'', which is ridiculously fast! If you don't specify a tempo, the computer will play at speed T2, which is 112 quarter notes per minute (moderato). Normally, the computer plays at volume 15; but you can change the volume. To switch to volume 4 (which is lower, quieter), say: PLAY "V4" You can switch to any volume from 1 to 31. If you try the bottom example in the main text, slow down the tempo: change T150 to T2. Exponents (384). For exponents, the TRS-80 Color Computer 2 (with extended color BASIC) uses the symbol ``'' instead of ``^''. Random integers (388). Omit the word RANDOMIZE. Random decimals (391). For a random decimal between 0 and 1, say RND(0) instead of RND. Clock (395). Your computer doesn't understand TIME$ or DATE$. Here's how to use the TIMER function. First, reset the TIMER to zero, by saying TIMER=0. Later, whenever you say PRINT TIMER/60, the computer will tell you how many seconds ago the timer was reset. Unfortunately, the TIMER lasts only 18 minutes; after 18 minutes, it resets itself to zero again. Types of numbers (397). All variables are reals: you can't create integer variables or double-precision variables. To create a real number, you can type as many digits as you wish, but the computer remembers just the first 10 digits accurately, and prints just the first 9 of them on your screen. RAM consumption (397). Each real number consumes 5 bytes of RAM. Omitting the question mark (406). In the INPUT statement, you can't replace the semicolon by a comma. Adjacent printing (407). You can't put a semicolon immediately after INPUT. INPUT$ (407). Instead of saying ___ 20 A$=INPUT$(1) say: 20 A$=INKEY$: IF A$="" THEN GO TO 20 Instead of saying INPUT$(4), you must INKEY$ one character at a time. Joystick (408). Say JOYSTK instead of STICK. The coordinates of the right joystick are JOYSTK(0) and JOYSTK(1). The coordinates of the left joystick are JOYSTK(2) and JOYSTK(3). When the computer comes to a line that mentions JOYSTK(0), the computer looks at both joysticks and computes JOYSTK(0), JOYSTK(1), JOYSTK(2), and JOYSTK(3). If your program mentions JOYSTK(1) or JOYSTK(2) or JOYSTK(3), without mentioning JOYSTK(0), the computer won't look at the joysticks. Mouse (408). Your computer's version of BASIC is not designed to work with a mouse. SWAP (409). Your computer doesn't understand SWAP, so use the alternative. ON ERROR GO TO (414). Your computer doesn't understand ON ERROR GO TO. OPEN FOR OUTPUT (415). Instead of saying OPEN ``SUE'' FOR OUTPUT AS 1, say OPEN ``O'',1,``SUE''. In the quotation marks, be sure to put the letter O, not a zero. OPEN FOR INPUT (415). Instead of saying OPEN ``SUE'' FOR INPUT AS 1, say OPEN ``I'',1,``SUE''. OPEN FOR APPEND (415). Your computer doesn't understand APPEND. LOF (416). Your computer doesn't understand the usual meaning of LOF(1). PUT (417). Instead of saying OPEN ``JIM'' AS 1 LEN=20, say OPEN ``D'',1,``JIM'',20. End of the file (417). LOF(1) is the number of records in the file (instead of being the number of bytes). Numerical data (417). Instead of using MKI$, MKS$, or MKD$, use MKN$. It MaKes a Number into a 5-byte string. Instead of using CVI, CVS, or CVD, use CVN. It ConVerts a 5-byte string to a Number. OTHER COMPUTERS Here's how to use BASIC on other kinds of computers. Tandy On page 443, I explained how to use BASIC on the TRS-80 Model 4 (and Model 4D and Model 4P). On page 445, I explained how to use BASIC on the TRS-80 Color Computer 2 (and Color Computer 1, Color Computer 3, and Micro Color Computer). If your computer is numbered between 1000 and 5000 (such as the Tandy 1000, 1200, 1400, 2000, 3000, 4000, or 5000), it's an IBM PC clone (explained on page 422). Here's how to use the TRS-80 Model 3. (Models 1, 2, 12, 16, 100, 102, 200, 6000, and Pocket Computers are similar.) The keyboard. Similar to Color Computer. You cannot create the symbols ``['', ``]'', and ``\'' by holding down the SHIFT key. To create the symbol ``['', tap the up-arrow key. To switch to lower case, tap the zero key while holding down the SHIFT key. Get started, if you don't have a disk. While holding down the BREAK key, flip on the power switch, which is underneath the computer's right side. The computer will say ``Cass''. If the writing looks fuzzy, turn the brightness and contrast dials, which are underneath the computer's left side. Press the ENTER key. The computer will say ``Memory Size''. Press ENTER again. The computer will say READY. Get started, if you have a disk. Follow Model 4's procedure, with these exceptions. . . . The disk you insert contains ``Model 3 TRSDOS'' instead of ``Model 4 TRSDOS''. After you enter the date (and press the ENTER key), the computer will say ``Enter Time''. Type the time by using a 24-hour clock; for example, if the time is 1:45 PM, type 13:45:00 and press ENTER. The computer will say ``How Many Files''; press ENTER. The computer will say ``Memory Size''; press ENTER. Then the computer will say READY. What if the computer gripes? Same as Model 4. Arrow keys. Similar to Model 4. When you press the D key, the character will be surrounded by exclamation points instead of backslashes. Print on paper. Your computer lacks a PRINT key. Instead of pressing a PRINT key, do the following: while depressing the down-arrow key and left SHIFT key simultaneously, tap the colon key. Your computer lacks an ECHO key. If you're using a disk, you can turn the echo on by typing this ___ CMD "Z","ON" and turn the echo off by typing this: CMD "Z","OFF" Save on disk. Similar to Model 4. To make the computer print the names of all programs on disk 0, say: CMD "D:0" To make the computer print the names of all programs on disk 1, say: CMD "D:1" Do not say FILES or SYSTEM ``DIR''. To turn a blank disk into a Radio Shack disk, do not say SYSTEM, etc. Instead, put the blank disk into the top drive, and then say: CMD "S" BACKUP :0 :1 The computer will ask, ``Source Disk Master Password?'' Type the word PASSWORD. The computer will copy all information from the bottom drive's disk to the blank disk. The computer will say ``TRSDOS Ready''. Type the word BASIC. The computer will say ``How Many Files''. Press the ENTER key. The computer will say ``Memory Size''. Press the ENTER key. The computer will say READY. How to choose a name. Same as Model 4. Tapes. Similar to Color Computer. The computer will say READY instead of OK, and will print a pair of asterisks instead of an F. The right asterisk flashes. Long variable names. Same as Color Computer. INPUT. Similar to Color Computer. If you're using a disk, the computer says ``Out of string space'' instead of ``?OS ERROR'', and says ``Out of memory'' instead of ``?OM ERROR''. If you don't say CLEAR, the computer reserves enough memory space to hold just 50 unknown characters. FOR...NEXT. Same as Model 4. Renumbering. To renumber, you must be using disks, and you must say NAME instead of RENUM. PAUSE key. To pause (or stop pausing), tap the @ key while holding down the SHIFT key. Zones. Each zone is 16 characters wide. Your screen has just 4 zones, so your screen is 64 characters wide. TAB. Same as Color Computer. LOCATE. Similar to Color Computer. Say 64 instead of 32. Pixels. The X coordinate goes from 0 to 127. The Y coordinate goes from 0 to 47. Say SET instead of PLOT. Your computer doesn't understand LINE, CIRCLE, PAINT, or colors. Sounds. Your computer can't produce sounds. Exponents. Instead of typing the symbol ``^'', type the symbol ``['', by pressing the up-arrow key. Random integers, decimals. Same as Model 4. Clock. To set the date to 01-24-1996, say: POKE 16924,1: POKE 16923,24: POKE 16922,96 To set the time to 13:45:07, say: POKE 16921,13: POKE 16920,45: POKE 16919,7 If you say PRINT TIME$, the computer will print both the date and time. Your computer doesn't understand TIMER. POKE. Same as Model 4, but uses cell #16419 instead of #2968, and normally makes the cursor be a double-underline (ASCII 176) instead of a single-underline. Omitting the question mark, adjacent printing, INPUT$. Same as Color Computer. Joystick. Your computer doesn't use joysticks. SWAP. Your computer doesn't understand SWAP, so use the alternative. OPEN FOR OUTPUT, INPUT, APPEND, LOF, PUT, end of the file. Same as Model 4. Laser 128 The Laser 128 computer imitates the Apple 2c (which is explained on page 431). Franklin Ace The Franklin Ace computer imitates the Apple 2+ (which is explained on page 431). Coleco Adam The Adam computer, manufactured by Coleco, resembles the Apple 2+ (which is explained on page 431). For a list of ways in which the Adam computer differs from the Apple 2+, get an earlier edition of The Secret Guide to Computers by phoning me at 617-666-2666. Computers that use CP/M The CP/M operating system is used by many old computers, such as the Kaypro 2, Kaypro 2X, Kaypro 4, Kaypro 10, and old relics manufactured by Osborne, Morrow, Cromemco, Vector, North Star, Xerox, and Zorba. On CP/M computers, begin by learning MBASIC (which is also called Microsoft BASIC and BASIC-80), since that version of BASIC is the easiest to learn. It resembles Tandy Model 4 BASIC (which is explained on page 443). For more details, get an earlier edition of The Secret Guide to Computers by phoning me at 617-666-2666. Atari, Texas Instruments, TimexSinclair For details, get an earlier edition of The Secret Guide to Computers by phoning me at 617-666-2666.